1
0
mirror of https://github.com/home-assistant/frontend.git synced 2025-12-20 10:48:44 +00:00

Use non-admin endpoint to subscribe to one lab feature (#28352)

This commit is contained in:
Paul Bottein
2025-12-05 17:34:22 +01:00
parent d197fd8f76
commit 0c68072f8f
5 changed files with 18 additions and 22 deletions

View File

@@ -31,8 +31,8 @@ export class HaSnowflakes extends SubscribeMixin(LitElement) {
this.hass!.connection, this.hass!.connection,
"frontend", "frontend",
"winter_mode", "winter_mode",
(enabled) => { (feature) => {
this._enabled = enabled; this._enabled = feature.enabled;
} }
), ),
]; ];

View File

@@ -101,22 +101,18 @@ export const subscribeLabFeatures = (
* Subscribe to a specific lab feature * Subscribe to a specific lab feature
* @param conn - The connection to the Home Assistant instance * @param conn - The connection to the Home Assistant instance
* @param domain - The domain of the lab feature * @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 * @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 = ( export const subscribeLabFeature = (
conn: Connection, conn: Connection,
domain: string, domain: string,
previewFeature: string, previewFeature: string,
onChange: (enabled: boolean) => void onChange: (feature: LabPreviewFeature) => void
) => ): Promise<() => void> =>
subscribeLabFeatures(conn, (features) => { conn.subscribeMessage<LabPreviewFeature>(onChange, {
const enabled = type: "labs/subscribe",
features.find( domain,
(feature) => preview_feature: previewFeature,
feature.domain === domain &&
feature.preview_feature === previewFeature
)?.enabled ?? false;
onChange(enabled);
}); });

View File

@@ -228,7 +228,7 @@ class DialogAddAutomationElement
private _unsub?: Promise<UnsubscribeFunc>; private _unsub?: Promise<UnsubscribeFunc>;
private _unsubscribeLabFeatures?: UnsubscribeFunc; private _unsubscribeLabFeatures?: Promise<UnsubscribeFunc>;
private _configEntryLookup: Record<string, ConfigEntry> = {}; private _configEntryLookup: Record<string, ConfigEntry> = {};
@@ -285,8 +285,8 @@ class DialogAddAutomationElement
this.hass.connection, this.hass.connection,
"automation", "automation",
"new_triggers_conditions", "new_triggers_conditions",
(enabled) => { (feature) => {
this._newTriggersAndConditions = enabled; this._newTriggersAndConditions = feature.enabled;
this._tab = this._newTriggersAndConditions ? "targets" : "groups"; this._tab = this._newTriggersAndConditions ? "targets" : "groups";
} }
); );
@@ -422,7 +422,7 @@ class DialogAddAutomationElement
this._unsub = undefined; this._unsub = undefined;
} }
if (this._unsubscribeLabFeatures) { if (this._unsubscribeLabFeatures) {
this._unsubscribeLabFeatures(); this._unsubscribeLabFeatures.then((unsub) => unsub());
this._unsubscribeLabFeatures = undefined; this._unsubscribeLabFeatures = undefined;
} }
} }

View File

@@ -94,8 +94,8 @@ export default class HaAutomationCondition extends SubscribeMixin(LitElement) {
this.hass!.connection, this.hass!.connection,
"automation", "automation",
"new_triggers_conditions", "new_triggers_conditions",
(enabled) => { (feature) => {
this._newTriggersAndConditions = enabled; this._newTriggersAndConditions = feature.enabled;
} }
), ),
]; ];

View File

@@ -89,8 +89,8 @@ export default class HaAutomationTrigger extends SubscribeMixin(LitElement) {
this.hass!.connection, this.hass!.connection,
"automation", "automation",
"new_triggers_conditions", "new_triggers_conditions",
(enabled) => { (feature) => {
this._newTriggersAndConditions = enabled; this._newTriggersAndConditions = feature.enabled;
} }
), ),
]; ];