diff --git a/src/components/ha-snowflakes.ts b/src/components/ha-snowflakes.ts index 45ffbc3e18b3..33440650a598 100644 --- a/src/components/ha-snowflakes.ts +++ b/src/components/ha-snowflakes.ts @@ -31,8 +31,8 @@ export class HaSnowflakes extends SubscribeMixin(LitElement) { this.hass!.connection, "frontend", "winter_mode", - (enabled) => { - this._enabled = enabled; + (feature) => { + this._enabled = feature.enabled; } ), ]; diff --git a/src/data/labs.ts b/src/data/labs.ts index 4eda13bc6f6e..2ef7b424223b 100644 --- a/src/data/labs.ts +++ b/src/data/labs.ts @@ -101,22 +101,18 @@ export const subscribeLabFeatures = ( * Subscribe to a specific lab feature * @param conn - The connection to the Home Assistant instance * @param domain - The domain of the lab feature - * @param previewFeature - The preview feature of the lab feature + * @param previewFeature - The preview feature identifier * @param onChange - The function to call when the lab feature changes - * @returns The unsubscribe function + * @returns A promise that resolves to the unsubscribe function */ export const subscribeLabFeature = ( conn: Connection, domain: string, previewFeature: string, - onChange: (enabled: boolean) => void -) => - subscribeLabFeatures(conn, (features) => { - const enabled = - features.find( - (feature) => - feature.domain === domain && - feature.preview_feature === previewFeature - )?.enabled ?? false; - onChange(enabled); + onChange: (feature: LabPreviewFeature) => void +): Promise<() => void> => + conn.subscribeMessage(onChange, { + type: "labs/subscribe", + domain, + preview_feature: previewFeature, }); diff --git a/src/panels/config/automation/add-automation-element-dialog.ts b/src/panels/config/automation/add-automation-element-dialog.ts index e50c0da0f9d5..3a69e260b030 100644 --- a/src/panels/config/automation/add-automation-element-dialog.ts +++ b/src/panels/config/automation/add-automation-element-dialog.ts @@ -228,7 +228,7 @@ class DialogAddAutomationElement private _unsub?: Promise; - private _unsubscribeLabFeatures?: UnsubscribeFunc; + private _unsubscribeLabFeatures?: Promise; private _configEntryLookup: Record = {}; @@ -285,8 +285,8 @@ class DialogAddAutomationElement this.hass.connection, "automation", "new_triggers_conditions", - (enabled) => { - this._newTriggersAndConditions = enabled; + (feature) => { + this._newTriggersAndConditions = feature.enabled; this._tab = this._newTriggersAndConditions ? "targets" : "groups"; } ); @@ -422,7 +422,7 @@ class DialogAddAutomationElement this._unsub = undefined; } if (this._unsubscribeLabFeatures) { - this._unsubscribeLabFeatures(); + this._unsubscribeLabFeatures.then((unsub) => unsub()); this._unsubscribeLabFeatures = undefined; } } diff --git a/src/panels/config/automation/condition/ha-automation-condition.ts b/src/panels/config/automation/condition/ha-automation-condition.ts index be3df9356188..31bcc063fcd7 100644 --- a/src/panels/config/automation/condition/ha-automation-condition.ts +++ b/src/panels/config/automation/condition/ha-automation-condition.ts @@ -94,8 +94,8 @@ export default class HaAutomationCondition extends SubscribeMixin(LitElement) { this.hass!.connection, "automation", "new_triggers_conditions", - (enabled) => { - this._newTriggersAndConditions = enabled; + (feature) => { + this._newTriggersAndConditions = feature.enabled; } ), ]; diff --git a/src/panels/config/automation/trigger/ha-automation-trigger.ts b/src/panels/config/automation/trigger/ha-automation-trigger.ts index c39be3c1e0be..6be41806c838 100644 --- a/src/panels/config/automation/trigger/ha-automation-trigger.ts +++ b/src/panels/config/automation/trigger/ha-automation-trigger.ts @@ -89,8 +89,8 @@ export default class HaAutomationTrigger extends SubscribeMixin(LitElement) { this.hass!.connection, "automation", "new_triggers_conditions", - (enabled) => { - this._newTriggersAndConditions = enabled; + (feature) => { + this._newTriggersAndConditions = feature.enabled; } ), ];