feat: Add support for config and initialized conditions (#1894)
These conditions are probably not hugely useful for most card users, but allows the inbuilt automation systems to be used for card internal operations. [skip ci]
This commit is contained in:
@@ -184,6 +184,18 @@ export class ConfigManager {
|
||||
await this._api.getDefaultManager().initializeIfNecessary(previousConfig);
|
||||
await this._api.getMediaPlayerManager().initializeIfNecessary(previousConfig);
|
||||
|
||||
// The config is only set in the state if the card is already fully
|
||||
// initialized. If not, the config will be set post initialization in the
|
||||
// InitializationManager.
|
||||
if (
|
||||
this._overriddenConfig &&
|
||||
this._api.getInitializationManager().isInitializedMandatory()
|
||||
) {
|
||||
this._api.getConditionStateManager().setState({
|
||||
config: this._overriddenConfig,
|
||||
});
|
||||
}
|
||||
|
||||
this._api.getCardElementManager().update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,6 +128,18 @@ export class InitializationManager {
|
||||
}
|
||||
|
||||
this._everInitialized = true;
|
||||
|
||||
// When the card is initialized, both the initialization state (will never
|
||||
// change again), and the config are set in the condition state. The
|
||||
// config is set here, rather than in the ConfigManager, in order to
|
||||
// ensure actions (that trigger on config change) are not run before hass
|
||||
// is available and the card is initialzied (the first config is set in
|
||||
// the card *before* hass is set in the card).
|
||||
this._api.getConditionStateManager().setState({
|
||||
config: config,
|
||||
initialized: this._everInitialized,
|
||||
});
|
||||
|
||||
this._api.getCardElementManager().update();
|
||||
}
|
||||
|
||||
|
||||
@@ -176,6 +176,7 @@ export interface CardInitializerAPI {
|
||||
getMicrophoneManager(): MicrophoneManager;
|
||||
|
||||
getCardElementManager(): CardElementManager;
|
||||
getConditionStateManager(): ConditionStateManager;
|
||||
getConfigManager(): ConfigManager;
|
||||
getDefaultManager(): DefaultManager;
|
||||
getEntityRegistryManager(): EntityRegistryManager;
|
||||
|
||||
Reference in New Issue
Block a user