Only include HA state in condition state if required.
This commit is contained in:
+27
-3
@@ -220,6 +220,11 @@ export class FrigateCard extends LitElement {
|
|||||||
protected _triggers: Map<string, Date> = new Map();
|
protected _triggers: Map<string, Date> = new Map();
|
||||||
protected _untriggerTimerID: number | null = null;
|
protected _untriggerTimerID: number | null = null;
|
||||||
|
|
||||||
|
// Whether or not to include HA state in ConditionState. Doing so increases
|
||||||
|
// CPU usage as HA state is pumped out very fast, so this is only enabled if
|
||||||
|
// the configuration is likely to consume it.
|
||||||
|
protected _needHAStateInConditionState = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the Home Assistant object.
|
* Set the Home Assistant object.
|
||||||
*/
|
*/
|
||||||
@@ -241,8 +246,10 @@ export class FrigateCard extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// HA entity state is part of the condition state.
|
if (this._needHAStateInConditionState) {
|
||||||
this._generateConditionState();
|
// HA entity state is part of the condition state.
|
||||||
|
this._generateConditionState();
|
||||||
|
}
|
||||||
|
|
||||||
// Dark mode may depend on HASS.
|
// Dark mode may depend on HASS.
|
||||||
this._setLightOrDarkMode();
|
this._setLightOrDarkMode();
|
||||||
@@ -287,8 +294,10 @@ export class FrigateCard extends LitElement {
|
|||||||
view: this._view?.view,
|
view: this._view?.view,
|
||||||
fullscreen: screenfull.isEnabled && screenfull.isFullscreen,
|
fullscreen: screenfull.isEnabled && screenfull.isFullscreen,
|
||||||
camera: this._view?.camera,
|
camera: this._view?.camera,
|
||||||
state: this._hass?.states,
|
|
||||||
mediaLoaded: !!this._currentMediaLoadedInfo,
|
mediaLoaded: !!this._currentMediaLoadedInfo,
|
||||||
|
...(this._needHAStateInConditionState && {
|
||||||
|
state: this._hass?.states,
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
// Update the components that need the new condition state. Passed directly
|
// Update the components that need the new condition state. Passed directly
|
||||||
@@ -991,6 +1000,21 @@ export class FrigateCard extends LitElement {
|
|||||||
this._generateConditionState();
|
this._generateConditionState();
|
||||||
this._setLightOrDarkMode();
|
this._setLightOrDarkMode();
|
||||||
this._untrigger();
|
this._untrigger();
|
||||||
|
|
||||||
|
const hasStateCondition = (): boolean => {
|
||||||
|
for (const override of this._config.overrides ?? []) {
|
||||||
|
if (override.conditions.state?.length) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// For elements there can be arbitrary custom elements that not related to
|
||||||
|
// this card so we cannot easily determine if state is used further down
|
||||||
|
// the chain by a custom:frigate-card-conditional element. Instead, include state
|
||||||
|
// if elements are configured at all.
|
||||||
|
return !!this._config.elements;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._needHAStateInConditionState = hasStateCondition();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
// TODO: Don't pump out conditionStates based on state?
|
|
||||||
|
|
||||||
import { deepRemoveDefaults } from './utils/zod.js';
|
import { deepRemoveDefaults } from './utils/zod.js';
|
||||||
import {
|
import {
|
||||||
frigateCardConfigSchema,
|
frigateCardConfigSchema,
|
||||||
FrigateCardConfig,
|
|
||||||
RawFrigateCardConfig,
|
RawFrigateCardConfig,
|
||||||
PerformanceConfig,
|
PerformanceConfig,
|
||||||
} from './types';
|
} from './types';
|
||||||
|
|||||||
Reference in New Issue
Block a user