fix: Clear the initialized condition state when the card is not usable (#2646)
The `initialized` state (used in conditions/triggers) was written once and never cleared, so it meant "has this card ever been initialized" while everything reading it took it as "is this card usable now". Home Assistant takes a card off the page and puts it back whenever its dashboard tab is left and returned to, so the card initialized again while the state claimed it was initialized throughout: `trigger: initialized` fired once per card rather than once per startup, and automations were dropped in between. The card lifecycle is now an explicit state machine (`SessionManager`), the only writer of `initialized`, which separates a card that is starting up from one initializing part of itself again while it runs. A new `ever` parameter (conditions/triggers) selects the old latched behaviour. `remote_control` uses that parameter to keep its two camera priorities correct under repeated starts. With `camera_priority: entity` the card now re-reads the entity every time it starts, so a camera selected while the card was away is picked up on return. With `camera_priority: card` the card writes the entity on its first start only, unchanged, since repeating that write would overwrite a camera the user had selected. Closes: #2642 BREAKING CHANGE: `condition: initialized` is now `false` whenever the card is not usable, and `trigger: initialized` fires each time the card starts up rather than only the first time. Set `ever: true` on either to keep the previous behaviour.
This commit is contained in:
+3
-2
@@ -360,7 +360,7 @@ export class AdvancedCameraCard extends LitElement {
|
||||
}
|
||||
|
||||
protected updated(): void {
|
||||
if (this._controller.getInitializationManager().isInitializedMandatory()) {
|
||||
if (this._controller.getInitializationManager().areMandatoryAspectsInitialized()) {
|
||||
void this._controller.getQueryStringManager().executeIfNecessary();
|
||||
}
|
||||
}
|
||||
@@ -461,6 +461,7 @@ export class AdvancedCameraCard extends LitElement {
|
||||
? html`<advanced-camera-card-loading
|
||||
.loaded=${this._controller
|
||||
.getInitializationManager()
|
||||
.getSessionManager()
|
||||
.wasEverInitialized()}
|
||||
.effectsManager=${this._config?.performance?.features
|
||||
.card_loading_effects !== false
|
||||
@@ -503,7 +504,7 @@ export class AdvancedCameraCard extends LitElement {
|
||||
</div>
|
||||
${this._renderMenuStatusContainer('bottom')}
|
||||
${this._config?.elements &&
|
||||
this._controller.getInitializationManager().isInitializedMandatory()
|
||||
this._controller.getInitializationManager().areMandatoryAspectsInitialized()
|
||||
? // Elements need to render after the main views so it can render 'on
|
||||
// top'. They are held until the card is initialized: the template
|
||||
// renderer loads lazily as a mandatory init aspect (when the
|
||||
|
||||
Reference in New Issue
Block a user