Skip to content

Commit

Permalink
Don't show keypad if default code
Browse files Browse the repository at this point in the history
  • Loading branch information
gjohansson-ST committed Apr 16, 2024
1 parent c2aeeaa commit 293acfb
Showing 1 changed file with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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, {
Expand Down

0 comments on commit 293acfb

Please sign in to comment.