diff --git a/src/state-control/alarm_control_panel/ha-state-control-alarm_control_panel-modes.ts b/src/state-control/alarm_control_panel/ha-state-control-alarm_control_panel-modes.ts index 585d14d9ca81..911de1033c4b 100644 --- a/src/state-control/alarm_control_panel/ha-state-control-alarm_control_panel-modes.ts +++ b/src/state-control/alarm_control_panel/ha-state-control-alarm_control_panel-modes.ts @@ -15,6 +15,7 @@ import { import { UNAVAILABLE } from "../../data/entity"; import { showEnterCodeDialog } from "../../dialogs/enter-code/show-enter-code-dialog"; import { HomeAssistant } from "../../types"; +import { getExtendedEntityRegistryEntry } from "../../data/entity_registry"; @customElement("ha-state-control-alarm_control_panel-modes") export class HaStateControlAlarmControlPanelModes extends LitElement { @@ -56,19 +57,30 @@ export class HaStateControlAlarmControlPanelModes extends LitElement { ) { const disarm = mode === "disarmed"; - const response = await showEnterCodeDialog(this, { - codeFormat: this.stateObj!.attributes.code_format, - title: this.hass!.localize( - `ui.card.alarm_control_panel.${disarm ? "disarm" : "arm"}` - ), - submitText: this.hass!.localize( - `ui.card.alarm_control_panel.${disarm ? "disarmn" : "arm"}` - ), - }); - if (response == null) { - throw new Error("cancel"); + const AlarmControlPanelRegistryEntry = + await getExtendedEntityRegistryEntry( + this.hass, + this.stateObj.entity_id + ).catch(() => undefined); + const defaultCode = + AlarmControlPanelRegistryEntry?.options?.alarm_control_panel + ?.default_code; + + if (!defaultCode) { + const response = await showEnterCodeDialog(this, { + codeFormat: this.stateObj!.attributes.code_format, + title: this.hass!.localize( + `ui.card.alarm_control_panel.${disarm ? "disarm" : "arm"}` + ), + submitText: this.hass!.localize( + `ui.card.alarm_control_panel.${disarm ? "disarmn" : "arm"}` + ), + }); + if (response == null) { + throw new Error("cancel"); + } + code = response; } - code = response; } await this.hass!.callService("alarm_control_panel", service, {