mirror of
https://github.com/home-assistant/frontend.git
synced 2025-12-20 02:38:53 +00:00
Use non-admin endpoint to subscribe to one lab feature (#28352)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
),
|
||||
];
|
||||
|
||||
@@ -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<LabPreviewFeature>(onChange, {
|
||||
type: "labs/subscribe",
|
||||
domain,
|
||||
preview_feature: previewFeature,
|
||||
});
|
||||
|
||||
@@ -228,7 +228,7 @@ class DialogAddAutomationElement
|
||||
|
||||
private _unsub?: Promise<UnsubscribeFunc>;
|
||||
|
||||
private _unsubscribeLabFeatures?: UnsubscribeFunc;
|
||||
private _unsubscribeLabFeatures?: Promise<UnsubscribeFunc>;
|
||||
|
||||
private _configEntryLookup: Record<string, ConfigEntry> = {};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
),
|
||||
];
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user