mirror of
https://github.com/home-assistant/frontend.git
synced 2025-12-20 02:38:53 +00:00
Resubscribe to descriptions when labs feat changes (#28145)
This commit is contained in:
@@ -246,6 +246,31 @@ class DialogAddAutomationElement
|
|||||||
) {
|
) {
|
||||||
this._calculateUsedDomains();
|
this._calculateUsedDomains();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (changedProps.has("_newTriggersAndConditions")) {
|
||||||
|
this._subscribeDescriptions();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private _subscribeDescriptions() {
|
||||||
|
this._unsubscribe();
|
||||||
|
if (this._params?.type === "trigger") {
|
||||||
|
this._triggerDescriptions = {};
|
||||||
|
this._unsub = subscribeTriggers(this.hass, (triggers) => {
|
||||||
|
this._triggerDescriptions = {
|
||||||
|
...this._triggerDescriptions,
|
||||||
|
...triggers,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
} else if (this._params?.type === "condition") {
|
||||||
|
this._conditionDescriptions = {};
|
||||||
|
this._unsub = subscribeConditions(this.hass, (conditions) => {
|
||||||
|
this._conditionDescriptions = {
|
||||||
|
...this._conditionDescriptions,
|
||||||
|
...conditions,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public hassSubscribe() {
|
public hassSubscribe() {
|
||||||
@@ -279,21 +304,11 @@ class DialogAddAutomationElement
|
|||||||
} else if (this._params?.type === "trigger") {
|
} else if (this._params?.type === "trigger") {
|
||||||
this.hass.loadBackendTranslation("triggers");
|
this.hass.loadBackendTranslation("triggers");
|
||||||
getTriggerIcons(this.hass);
|
getTriggerIcons(this.hass);
|
||||||
this._unsub = subscribeTriggers(this.hass, (triggers) => {
|
this._subscribeDescriptions();
|
||||||
this._triggerDescriptions = {
|
|
||||||
...this._triggerDescriptions,
|
|
||||||
...triggers,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
} else if (this._params?.type === "condition") {
|
} else if (this._params?.type === "condition") {
|
||||||
this.hass.loadBackendTranslation("conditions");
|
this.hass.loadBackendTranslation("conditions");
|
||||||
getConditionIcons(this.hass);
|
getConditionIcons(this.hass);
|
||||||
this._unsub = subscribeConditions(this.hass, (conditions) => {
|
this._subscribeDescriptions();
|
||||||
this._conditionDescriptions = {
|
|
||||||
...this._conditionDescriptions,
|
|
||||||
...conditions,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener("resize", this._updateNarrow);
|
window.addEventListener("resize", this._updateNarrow);
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { mdiDragHorizontalVariant, mdiPlus } from "@mdi/js";
|
import { mdiDragHorizontalVariant, mdiPlus } from "@mdi/js";
|
||||||
import deepClone from "deep-clone-simple";
|
import deepClone from "deep-clone-simple";
|
||||||
import type { HassServiceTarget } from "home-assistant-js-websocket";
|
import type {
|
||||||
|
HassServiceTarget,
|
||||||
|
UnsubscribeFunc,
|
||||||
|
} from "home-assistant-js-websocket";
|
||||||
import type { PropertyValues } from "lit";
|
import type { PropertyValues } from "lit";
|
||||||
import { html, LitElement, nothing } from "lit";
|
import { html, LitElement, nothing } from "lit";
|
||||||
import { customElement, property, queryAll, state } from "lit/decorators";
|
import { customElement, property, queryAll, state } from "lit/decorators";
|
||||||
@@ -25,6 +28,7 @@ import {
|
|||||||
CONDITION_BUILDING_BLOCKS,
|
CONDITION_BUILDING_BLOCKS,
|
||||||
subscribeConditions,
|
subscribeConditions,
|
||||||
} from "../../../../data/condition";
|
} from "../../../../data/condition";
|
||||||
|
import { subscribeLabFeatures } from "../../../../data/labs";
|
||||||
import { SubscribeMixin } from "../../../../mixins/subscribe-mixin";
|
import { SubscribeMixin } from "../../../../mixins/subscribe-mixin";
|
||||||
import type { HomeAssistant } from "../../../../types";
|
import type { HomeAssistant } from "../../../../types";
|
||||||
import {
|
import {
|
||||||
@@ -74,19 +78,52 @@ export default class HaAutomationCondition extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
private _conditionKeys = new WeakMap<Condition, string>();
|
private _conditionKeys = new WeakMap<Condition, string>();
|
||||||
|
|
||||||
|
private _unsub?: Promise<UnsubscribeFunc>;
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
@state() private _newTriggersAndConditions = false;
|
||||||
|
|
||||||
|
public disconnectedCallback() {
|
||||||
|
super.disconnectedCallback();
|
||||||
|
this._unsubscribe();
|
||||||
|
}
|
||||||
|
|
||||||
protected hassSubscribe() {
|
protected hassSubscribe() {
|
||||||
return [
|
return [
|
||||||
subscribeConditions(this.hass, (conditions) =>
|
subscribeLabFeatures(this.hass!.connection, (features) => {
|
||||||
this._addConditions(conditions)
|
this._newTriggersAndConditions =
|
||||||
),
|
features.find(
|
||||||
|
(feature) =>
|
||||||
|
feature.domain === "automation" &&
|
||||||
|
feature.preview_feature === "new_triggers_conditions"
|
||||||
|
)?.enabled ?? false;
|
||||||
|
}),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private _addConditions(conditions: ConditionDescriptions) {
|
private _subscribeDescriptions() {
|
||||||
this._conditionDescriptions = {
|
this._unsubscribe();
|
||||||
...this._conditionDescriptions,
|
this._conditionDescriptions = {};
|
||||||
...conditions,
|
this._unsub = subscribeConditions(this.hass, (descriptions) => {
|
||||||
};
|
this._conditionDescriptions = {
|
||||||
|
...this._conditionDescriptions,
|
||||||
|
...descriptions,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private _unsubscribe() {
|
||||||
|
if (this._unsub) {
|
||||||
|
this._unsub.then((unsub) => unsub());
|
||||||
|
this._unsub = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected willUpdate(changedProperties: PropertyValues): void {
|
||||||
|
super.willUpdate(changedProperties);
|
||||||
|
if (changedProperties.has("_newTriggersAndConditions")) {
|
||||||
|
this._subscribeDescriptions();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected firstUpdated(changedProps: PropertyValues) {
|
protected firstUpdated(changedProps: PropertyValues) {
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { mdiDragHorizontalVariant, mdiPlus } from "@mdi/js";
|
import { mdiDragHorizontalVariant, mdiPlus } from "@mdi/js";
|
||||||
import deepClone from "deep-clone-simple";
|
import deepClone from "deep-clone-simple";
|
||||||
import type { HassServiceTarget } from "home-assistant-js-websocket";
|
import type {
|
||||||
|
HassServiceTarget,
|
||||||
|
UnsubscribeFunc,
|
||||||
|
} from "home-assistant-js-websocket";
|
||||||
import type { PropertyValues } from "lit";
|
import type { PropertyValues } from "lit";
|
||||||
import { html, LitElement, nothing } from "lit";
|
import { html, LitElement, nothing } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
@@ -21,6 +24,7 @@ import {
|
|||||||
type Trigger,
|
type Trigger,
|
||||||
type TriggerList,
|
type TriggerList,
|
||||||
} from "../../../../data/automation";
|
} from "../../../../data/automation";
|
||||||
|
import { subscribeLabFeatures } from "../../../../data/labs";
|
||||||
import type { TriggerDescriptions } from "../../../../data/trigger";
|
import type { TriggerDescriptions } from "../../../../data/trigger";
|
||||||
import { isTriggerList, subscribeTriggers } from "../../../../data/trigger";
|
import { isTriggerList, subscribeTriggers } from "../../../../data/trigger";
|
||||||
import { SubscribeMixin } from "../../../../mixins/subscribe-mixin";
|
import { SubscribeMixin } from "../../../../mixins/subscribe-mixin";
|
||||||
@@ -67,16 +71,54 @@ export default class HaAutomationTrigger extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
private _triggerKeys = new WeakMap<Trigger, string>();
|
private _triggerKeys = new WeakMap<Trigger, string>();
|
||||||
|
|
||||||
|
private _unsub?: Promise<UnsubscribeFunc>;
|
||||||
|
|
||||||
@state() private _triggerDescriptions: TriggerDescriptions = {};
|
@state() private _triggerDescriptions: TriggerDescriptions = {};
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
@state() private _newTriggersAndConditions = false;
|
||||||
|
|
||||||
|
public disconnectedCallback() {
|
||||||
|
super.disconnectedCallback();
|
||||||
|
this._unsubscribe();
|
||||||
|
}
|
||||||
|
|
||||||
protected hassSubscribe() {
|
protected hassSubscribe() {
|
||||||
return [
|
return [
|
||||||
subscribeTriggers(this.hass, (triggers) => this._addTriggers(triggers)),
|
subscribeLabFeatures(this.hass!.connection, (features) => {
|
||||||
|
this._newTriggersAndConditions =
|
||||||
|
features.find(
|
||||||
|
(feature) =>
|
||||||
|
feature.domain === "automation" &&
|
||||||
|
feature.preview_feature === "new_triggers_conditions"
|
||||||
|
)?.enabled ?? false;
|
||||||
|
}),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private _addTriggers(triggers: TriggerDescriptions) {
|
private _subscribeDescriptions() {
|
||||||
this._triggerDescriptions = { ...this._triggerDescriptions, ...triggers };
|
this._unsubscribe();
|
||||||
|
this._triggerDescriptions = {};
|
||||||
|
this._unsub = subscribeTriggers(this.hass, (descriptions) => {
|
||||||
|
this._triggerDescriptions = {
|
||||||
|
...this._triggerDescriptions,
|
||||||
|
...descriptions,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private _unsubscribe() {
|
||||||
|
if (this._unsub) {
|
||||||
|
this._unsub.then((unsub) => unsub());
|
||||||
|
this._unsub = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected willUpdate(changedProperties: PropertyValues): void {
|
||||||
|
super.willUpdate(changedProperties);
|
||||||
|
if (changedProperties.has("_newTriggersAndConditions")) {
|
||||||
|
this._subscribeDescriptions();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected firstUpdated(changedProps: PropertyValues) {
|
protected firstUpdated(changedProps: PropertyValues) {
|
||||||
|
|||||||
Reference in New Issue
Block a user