mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
More alarm arming options in more-info dialog (#15452)
* More alarm arming options in more-info dialog * minor change to null handling * Update src/dialogs/more-info/controls/more-info-alarm_control_panel.ts Co-authored-by: Paul Bottein <paul.bottein@gmail.com> * Update src/dialogs/more-info/controls/more-info-alarm_control_panel.ts Co-authored-by: Paul Bottein <paul.bottein@gmail.com> --------- Co-authored-by: Paul Bottein <paul.bottein@gmail.com>
This commit is contained in:
parent
cb85bc054a
commit
3b1bc37f53
@ -3,6 +3,15 @@ import { HomeAssistant } from "../types";
|
|||||||
export const FORMAT_TEXT = "text";
|
export const FORMAT_TEXT = "text";
|
||||||
export const FORMAT_NUMBER = "number";
|
export const FORMAT_NUMBER = "number";
|
||||||
|
|
||||||
|
export const enum AlarmControlPanelEntityFeature {
|
||||||
|
ARM_HOME = 1,
|
||||||
|
ARM_AWAY = 2,
|
||||||
|
ARM_NIGHT = 4,
|
||||||
|
TRIGGER = 8,
|
||||||
|
ARM_CUSTOM_BYPASS = 16,
|
||||||
|
ARM_VACATION = 32,
|
||||||
|
}
|
||||||
|
|
||||||
export const callAlarmAction = (
|
export const callAlarmAction = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entity: string,
|
entity: string,
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
import "@material/mwc-button";
|
import "@material/mwc-button";
|
||||||
import type { HassEntity } from "home-assistant-js-websocket";
|
import type { HassEntity } from "home-assistant-js-websocket";
|
||||||
import { css, html, LitElement, TemplateResult } from "lit";
|
import { css, html, LitElement, PropertyValues, TemplateResult } from "lit";
|
||||||
import { customElement, property, query } from "lit/decorators";
|
import { customElement, property, state, query } from "lit/decorators";
|
||||||
import { classMap } from "lit/directives/class-map";
|
import { classMap } from "lit/directives/class-map";
|
||||||
import "../../../components/ha-textfield";
|
import "../../../components/ha-textfield";
|
||||||
|
import { supportsFeature } from "../../../common/entity/supports-feature";
|
||||||
import type { HaTextField } from "../../../components/ha-textfield";
|
import type { HaTextField } from "../../../components/ha-textfield";
|
||||||
import {
|
import {
|
||||||
callAlarmAction,
|
callAlarmAction,
|
||||||
FORMAT_NUMBER,
|
FORMAT_NUMBER,
|
||||||
|
AlarmControlPanelEntityFeature,
|
||||||
} from "../../../data/alarm_control_panel";
|
} from "../../../data/alarm_control_panel";
|
||||||
import type { HomeAssistant } from "../../../types";
|
import type { HomeAssistant } from "../../../types";
|
||||||
|
|
||||||
const BUTTONS = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "", "0", "clear"];
|
const BUTTONS = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "", "0", "clear"];
|
||||||
const ARM_ACTIONS = ["arm_home", "arm_away"];
|
|
||||||
const DISARM_ACTIONS = ["disarm"];
|
const DISARM_ACTIONS = ["disarm"];
|
||||||
|
|
||||||
@customElement("more-info-alarm_control_panel")
|
@customElement("more-info-alarm_control_panel")
|
||||||
@ -21,8 +22,51 @@ export class MoreInfoAlarmControlPanel extends LitElement {
|
|||||||
|
|
||||||
@property({ attribute: false }) public stateObj?: HassEntity;
|
@property({ attribute: false }) public stateObj?: HassEntity;
|
||||||
|
|
||||||
|
@state() private _armActions: string[] = [];
|
||||||
|
|
||||||
@query("#alarmCode") private _input?: HaTextField;
|
@query("#alarmCode") private _input?: HaTextField;
|
||||||
|
|
||||||
|
public willUpdate(changedProps: PropertyValues<this>) {
|
||||||
|
super.willUpdate(changedProps);
|
||||||
|
|
||||||
|
if (!this.stateObj || !changedProps.has("stateObj")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._armActions = [];
|
||||||
|
if (
|
||||||
|
supportsFeature(this.stateObj, AlarmControlPanelEntityFeature.ARM_HOME)
|
||||||
|
) {
|
||||||
|
this._armActions.push("arm_home");
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
supportsFeature(this.stateObj, AlarmControlPanelEntityFeature.ARM_AWAY)
|
||||||
|
) {
|
||||||
|
this._armActions.push("arm_away");
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
supportsFeature(this.stateObj, AlarmControlPanelEntityFeature.ARM_NIGHT)
|
||||||
|
) {
|
||||||
|
this._armActions.push("arm_night");
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
supportsFeature(
|
||||||
|
this.stateObj,
|
||||||
|
AlarmControlPanelEntityFeature.ARM_CUSTOM_BYPASS
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
this._armActions.push("arm_custom_bypass");
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
supportsFeature(
|
||||||
|
this.stateObj,
|
||||||
|
AlarmControlPanelEntityFeature.ARM_VACATION
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
this._armActions.push("arm_vacation");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
if (!this.hass || !this.stateObj) {
|
if (!this.hass || !this.stateObj) {
|
||||||
return html``;
|
return html``;
|
||||||
@ -72,7 +116,7 @@ export class MoreInfoAlarmControlPanel extends LitElement {
|
|||||||
`}
|
`}
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
${(this.stateObj.state === "disarmed"
|
${(this.stateObj.state === "disarmed"
|
||||||
? ARM_ACTIONS
|
? this._armActions
|
||||||
: DISARM_ACTIONS
|
: DISARM_ACTIONS
|
||||||
).map(
|
).map(
|
||||||
(stateAction) => html`
|
(stateAction) => html`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user