Reject HASS if not currently connected.
This commit is contained in:
+11
-11
@@ -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.has('hass') &&
|
||||||
changedProps.size == 1 &&
|
changedProps.size == 1 &&
|
||||||
this._imageConfig?.mode === 'camera' &&
|
this._imageConfig?.mode === 'camera' &&
|
||||||
cameraEntity) {
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user