Skip to content

Commit

Permalink
Add default code to alarm_control_panel
Browse files Browse the repository at this point in the history
  • Loading branch information
gjohansson-ST committed Apr 16, 2024
1 parent 25c702a commit c2aeeaa
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/data/entity_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ export interface LockEntityOptions {
default_code?: string | null;
}

export interface AlarmControlPanelEntityOptions {
default_code?: string | null;
}

export interface WeatherEntityOptions {
precipitation_unit?: string | null;
pressure_unit?: string | null;
Expand All @@ -112,6 +116,7 @@ export interface SwitchAsXEntityOptions {
export interface EntityRegistryOptions {
number?: NumberEntityOptions;
sensor?: SensorEntityOptions;
alarm_control_panel?: AlarmControlPanelEntityOptions;
lock?: LockEntityOptions;
weather?: WeatherEntityOptions;
light?: LightEntityOptions;
Expand All @@ -134,6 +139,7 @@ export interface EntityRegistryEntryUpdateParams {
| SensorEntityOptions
| NumberEntityOptions
| LockEntityOptions
| AlarmControlPanelEntityOptions
| WeatherEntityOptions
| LightEntityOptions;
aliases?: string[];
Expand Down
27 changes: 27 additions & 0 deletions src/panels/config/entities/entity-registry-settings-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {
updateDeviceRegistryEntry,
} from "../../../data/device_registry";
import {
AlarmControlPanelEntityOptions,
EntityRegistryEntry,
EntityRegistryEntryUpdateParams,
ExtEntityRegistryEntry,
Expand Down Expand Up @@ -257,6 +258,10 @@ export class EntityRegistrySettingsEditor extends LitElement {
this._defaultCode = this.entry.options?.lock?.default_code;
}

if (domain === "alarm_control_panel") {
this._defaultCode = this.entry.options?.alarm_control_panel?.default_code;
}

if (domain === "weather") {
const stateObj: HassEntity | undefined =
this.hass.states[this.entry.entity_id];
Expand Down Expand Up @@ -583,6 +588,19 @@ export class EntityRegistrySettingsEditor extends LitElement {
></ha-textfield>
`
: ""}
${domain === "alarm_control_panel"
? html`
<ha-textfield
.value=${this._defaultCode == null ? "" : this._defaultCode}
.label=${this.hass.localize(
"ui.dialogs.entity_registry.editor.default_code"
)}
type="password"
.disabled=${this.disabled}
@input=${this._defaultcodeChanged}
></ha-textfield>
`
: ""}
${domain === "sensor" &&
this._deviceClass &&
stateObj?.attributes.unit_of_measurement &&
Expand Down Expand Up @@ -1071,6 +1089,15 @@ export class EntityRegistrySettingsEditor extends LitElement {
params.options = this.entry.options?.[domain] || {};
(params.options as LockEntityOptions).default_code = this._defaultCode;
}
if (
domain === "alarm_control_panel" &&
this.entry.options?.[domain]?.default_code !== this._defaultCode
) {
params.options_domain = domain;
params.options = this.entry.options?.[domain] || {};
(params.options as AlarmControlPanelEntityOptions).default_code =
this._defaultCode;
}
if (
domain === "weather" &&
(stateObj?.attributes?.precipitation_unit !== this._precipitation_unit ||
Expand Down

0 comments on commit c2aeeaa

Please sign in to comment.