From cc8221ea2bd9de4b66574d23be9bc579dc0f1410 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Mon, 6 May 2024 18:42:03 +0000 Subject: [PATCH] Review --- .../lovelace/cards/hui-alarm-panel-card.ts | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/panels/lovelace/cards/hui-alarm-panel-card.ts b/src/panels/lovelace/cards/hui-alarm-panel-card.ts index ecfce5fac28c..517ad4535930 100644 --- a/src/panels/lovelace/cards/hui-alarm-panel-card.ts +++ b/src/panels/lovelace/cards/hui-alarm-panel-card.ts @@ -30,6 +30,10 @@ import type { HomeAssistant } from "../../../types"; import { findEntities } from "../common/find-entities"; import { createEntityNotFoundWarning } from "../components/hui-warning"; import type { LovelaceCard } from "../types"; +import { + ExtEntityRegistryEntry, + getExtendedEntityRegistryEntry, +} from "../../../data/entity_registry"; import { AlarmPanelCardConfig, AlarmPanelCardConfigState } from "./types"; const BUTTONS = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "", "0", "clear"]; @@ -99,6 +103,8 @@ class HuiAlarmPanelCard extends LitElement implements LovelaceCard { @state() private _config?: AlarmPanelCardConfig; + @state() private _entry?: ExtEntityRegistryEntry | null; + @query("#alarmCode") private _input?: HaTextField; public async getCardSize(): Promise { @@ -143,6 +149,7 @@ class HuiAlarmPanelCard extends LitElement implements LovelaceCard { ) { applyThemesOnElement(this, this.hass.themes, this._config.theme); } + this._loadEntityRegistryEntry(); } protected shouldUpdate(changedProps: PropertyValues): boolean { @@ -165,6 +172,20 @@ class HuiAlarmPanelCard extends LitElement implements LovelaceCard { ); } + private async _loadEntityRegistryEntry() { + if (!this._config!.entity) { + return; + } + try { + this._entry = await getExtendedEntityRegistryEntry( + this.hass!, + this._config!.entity + ); + } catch (e) { + this._entry = null; + } + } + protected render() { if (!this._config || !this.hass) { return nothing; @@ -184,6 +205,8 @@ class HuiAlarmPanelCard extends LitElement implements LovelaceCard { const stateLabel = this._stateDisplay(stateObj.state); + const defaultCode = this._entry?.options?.alarm_control_panel?.default_code; + return html`

@@ -222,7 +245,7 @@ class HuiAlarmPanelCard extends LitElement implements LovelaceCard { ` )} - ${!stateObj.attributes.code_format + ${!stateObj.attributes.code_format || defaultCode! ? nothing : html` `} - ${stateObj.attributes.code_format !== FORMAT_NUMBER + ${stateObj.attributes.code_format !== FORMAT_NUMBER || defaultCode! ? nothing : html`