From e642c8000327006eb3638466650eaab19d9def28 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Wed, 9 Oct 2024 19:28:50 +0200 Subject: [PATCH] Fix device automations --- .../device/ha-device-automation-picker.ts | 2 ++ .../lovelace/components/hui-action-editor.ts | 23 +++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/components/device/ha-device-automation-picker.ts b/src/components/device/ha-device-automation-picker.ts index c430e20134..6351eb5e6b 100644 --- a/src/components/device/ha-device-automation-picker.ts +++ b/src/components/device/ha-device-automation-picker.ts @@ -3,6 +3,7 @@ import "@material/mwc-list/mwc-list-item"; import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; import { property, state } from "lit/decorators"; import { fireEvent } from "../../common/dom/fire_event"; +import { stopPropagation } from "../../common/dom/stop_propagation"; import { fullEntitiesContext } from "../../data/context"; import { DeviceAutomation, @@ -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/panels/lovelace/components/hui-action-editor.ts b/src/panels/lovelace/components/hui-action-editor.ts index 044a862e45..3124cd1446 100644 --- a/src/panels/lovelace/components/hui-action-editor.ts +++ b/src/panels/lovelace/components/hui-action-editor.ts @@ -1,3 +1,5 @@ +import { ContextProvider } from "@lit-labs/context"; +import { UnsubscribeFunc } from "home-assistant-js-websocket"; import { css, CSSResultGroup, @@ -14,7 +16,10 @@ import "../../../components/ha-assist-pipeline-picker"; import { HaFormSchema, SchemaUnion } from "../../../components/ha-form/types"; import "../../../components/ha-help-tooltip"; import "../../../components/ha-navigation-picker"; +import { HaSelect } from "../../../components/ha-select"; import "../../../components/ha-service-control"; +import { fullEntitiesContext } from "../../../data/context"; +import { subscribeEntityRegistry } from "../../../data/entity_registry"; import { ActionConfig, CallServiceActionConfig, @@ -22,9 +27,9 @@ import { UrlActionConfig, } from "../../../data/lovelace/config/action"; import { ServiceAction } from "../../../data/script"; +import { SubscribeMixin } from "../../../mixins/subscribe-mixin"; import { HomeAssistant } from "../../../types"; import { EditorTarget } from "../editor/types"; -import { HaSelect } from "../../../components/ha-select"; export type UiAction = Exclude; @@ -81,7 +86,7 @@ const SEQUENCE_SCHEMA = [ ] as const satisfies readonly HaFormSchema[]; @customElement("hui-action-editor") -export class HuiActionEditor extends LitElement { +export class HuiActionEditor extends SubscribeMixin(LitElement) { @property({ attribute: false }) public config?: ActionConfig; @property() public label?: string; @@ -96,6 +101,19 @@ export class HuiActionEditor extends LitElement { @query("ha-select") private _select!: HaSelect; + private _entitiesContext = new ContextProvider(this, { + context: fullEntitiesContext, + initialValue: [], + }); + + public hassSubscribe(): UnsubscribeFunc[] { + return [ + subscribeEntityRegistry(this.hass!.connection!, (entities) => { + this._entitiesContext.setValue(entities); + }), + ]; + } + get _navigation_path(): string { const config = this.config as NavigateActionConfig | undefined; return config?.navigation_path || ""; @@ -132,6 +150,7 @@ export class HuiActionEditor extends LitElement { protected firstUpdated(_changedProperties: PropertyValues): void { this.hass!.loadFragmentTranslation("config"); + this.hass!.loadBackendTranslation("device_automation"); } protected render() {