diff --git a/src/components/device/ha-device-automation-picker.ts b/src/components/device/ha-device-automation-picker.ts index b79ac97e41ca..e0847f3ba77b 100644 --- a/src/components/device/ha-device-automation-picker.ts +++ b/src/components/device/ha-device-automation-picker.ts @@ -12,6 +12,7 @@ import { import type { EntityRegistryEntry } from "../../data/entity_registry"; import type { HomeAssistant } from "../../types"; import "../ha-select"; +import { stopPropagation } from "../../common/dom/stop_propagation"; const NO_AUTOMATION_KEY = "NO_AUTOMATION"; const UNKNOWN_AUTOMATION_KEY = "UNKNOWN_AUTOMATION"; @@ -103,6 +104,7 @@ export abstract class HaDeviceAutomationPicker< .label=${this.label} .value=${value} @selected=${this._automationChanged} + @closed=${stopPropagation} .disabled=${this._automations.length === 0} > ${value === NO_AUTOMATION_KEY diff --git a/src/components/ha-selector/ha-selector-action.ts b/src/components/ha-selector/ha-selector-action.ts index 255340b787d0..90c0b9bd621e 100644 --- a/src/components/ha-selector/ha-selector-action.ts +++ b/src/components/ha-selector/ha-selector-action.ts @@ -1,14 +1,22 @@ +import { ContextProvider, consume } from "@lit-labs/context"; import { css, html, LitElement, nothing } from "lit"; -import { customElement, property } from "lit/decorators"; +import { customElement, property, state } from "lit/decorators"; import memoizeOne from "memoize-one"; +import type { UnsubscribeFunc } from "home-assistant-js-websocket"; +import { fullEntitiesContext } from "../../data/context"; import type { Action } from "../../data/script"; import { migrateAutomationAction } from "../../data/script"; import type { ActionSelector } from "../../data/selector"; import "../../panels/config/automation/action/ha-automation-action"; import type { HomeAssistant } from "../../types"; +import { + subscribeEntityRegistry, + type EntityRegistryEntry, +} from "../../data/entity_registry"; +import { SubscribeMixin } from "../../mixins/subscribe-mixin"; @customElement("ha-selector-action") -export class HaActionSelector extends LitElement { +export class HaActionSelector extends SubscribeMixin(LitElement) { @property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public selector!: ActionSelector; @@ -19,6 +27,14 @@ export class HaActionSelector extends LitElement { @property({ type: Boolean, reflect: true }) public disabled = false; + @state() + @consume({ context: fullEntitiesContext, subscribe: true }) + _entityReg: EntityRegistryEntry[] | undefined; + + @state() private _entitiesContext; + + protected hassSubscribeRequiredHostProps = ["_entitiesContext"]; + private _actions = memoizeOne((action: Action | undefined) => { if (!action) { return []; @@ -26,6 +42,23 @@ export class HaActionSelector extends LitElement { return migrateAutomationAction(action); }); + protected firstUpdated() { + if (!this._entityReg) { + this._entitiesContext = new ContextProvider(this, { + context: fullEntitiesContext, + initialValue: [], + }); + } + } + + public hassSubscribe(): UnsubscribeFunc[] { + return [ + subscribeEntityRegistry(this.hass.connection!, (entities) => { + this._entitiesContext.setValue(entities); + }), + ]; + } + protected render() { return html` ${this.label ? html`` : nothing} diff --git a/src/panels/config/automation/action/types/ha-automation-action-device_id.ts b/src/panels/config/automation/action/types/ha-automation-action-device_id.ts index e5f4f3d9d4b5..dd5f7e649231 100644 --- a/src/panels/config/automation/action/types/ha-automation-action-device_id.ts +++ b/src/panels/config/automation/action/types/ha-automation-action-device_id.ts @@ -127,6 +127,7 @@ export class HaDeviceAction extends LitElement { } protected firstUpdated() { + this.hass.loadBackendTranslation("device_automation"); if (!this._capabilities) { this._getCapabilities(); } @@ -135,8 +136,8 @@ export class HaDeviceAction extends LitElement { } } - protected updated(changedPros) { - const prevAction = changedPros.get("action"); + protected updated(changedProps) { + const prevAction = changedProps.get("action"); if ( prevAction && !deviceAutomationsEqual(this._entityReg, prevAction, this.action) diff --git a/src/panels/config/automation/condition/types/ha-automation-condition-device.ts b/src/panels/config/automation/condition/types/ha-automation-condition-device.ts index 70ae2128e171..de33f9817b8d 100644 --- a/src/panels/config/automation/condition/types/ha-automation-condition-device.ts +++ b/src/panels/config/automation/condition/types/ha-automation-condition-device.ts @@ -128,6 +128,7 @@ export class HaDeviceCondition extends LitElement { } protected firstUpdated() { + this.hass.loadBackendTranslation("device_automation"); if (!this._capabilities) { this._getCapabilities(); } @@ -136,8 +137,8 @@ export class HaDeviceCondition extends LitElement { } } - protected updated(changedPros) { - const prevCondition = changedPros.get("condition"); + protected updated(changedProps) { + const prevCondition = changedProps.get("condition"); if ( prevCondition && !deviceAutomationsEqual(this._entityReg, prevCondition, this.condition) diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-device.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-device.ts index ad72162fd7b6..d0bc48b39946 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-device.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-device.ts @@ -132,6 +132,7 @@ export class HaDeviceTrigger extends LitElement { } protected firstUpdated() { + this.hass.loadBackendTranslation("device_automation"); if (!this._capabilities) { this._getCapabilities(); }