Reject HASS if not currently connected.

This commit is contained in:
Dermot Duffy
2022-03-05 17:15:45 -08:00
parent fed2cba89a
commit cf76393357
+13 -13
View File
@@ -73,26 +73,28 @@ export class FrigateCardImage extends LitElement {
} }
// If camera mode is enabled, reject all updates if hass is older than // If camera mode is enabled, reject all updates if hass is older than
// HASS_REJECTION_CUTOFF_MS. By using an older hass (even if it is not the // HASS_REJECTION_CUTOFF_MS or if HASS is not currently connected. By using
// property being updated), we run the risk that the JS has an old access // an older hass (even if it is not the property being updated), we run the
// token for the camera, and that results in a notification on the HA UI // risk that the JS has an old access token for the camera, and that results
// about a failed login. See // in a notification on the HA UI about a failed login. See
// https://github.com/dermotduffy/frigate-hass-card/issues/398 . // https://github.com/dermotduffy/frigate-hass-card/issues/398 .
const cameraEntity = this._getCameraEntity(); const cameraEntity = this._getCameraEntity();
const state = cameraEntity ? this.hass.states[cameraEntity] : undefined; const state = cameraEntity ? this.hass.states[cameraEntity] : undefined;
if ( if (
this._imageConfig?.mode === 'camera' && this._imageConfig?.mode === 'camera' &&
state && (!this.hass.connected ||
Date.now() - Date.parse(state.last_updated) >= !state ||
HASS_REJECTION_CUTOFF_MS Date.now() - Date.parse(state.last_updated) >= HASS_REJECTION_CUTOFF_MS)
) { ) {
return false; return false;
} }
if (changedProps.has('hass') && if (
changedProps.size == 1 && changedProps.has('hass') &&
this._imageConfig?.mode === 'camera' && changedProps.size == 1 &&
cameraEntity) { this._imageConfig?.mode === 'camera' &&
cameraEntity
) {
if (shouldUpdateBasedOnHass(this.hass, changedProps.get('hass'), [cameraEntity])) { if (shouldUpdateBasedOnHass(this.hass, changedProps.get('hass'), [cameraEntity])) {
// If the state of the camera entity has changed, remove the cached // If the state of the camera entity has changed, remove the cached
// value (will be re-calculated in willUpdate). This is important to // value (will be re-calculated in willUpdate). This is important to
@@ -105,8 +107,6 @@ export class FrigateCardImage extends LitElement {
return true; return true;
} }
/** /**
* Ensure there is a cached value before an update. * Ensure there is a cached value before an update.
* @param _changedProps The changed properties * @param _changedProps The changed properties