+
+
+
+
3
+
6
+
9
+
[[_label(localize, "clear_code")]]
+
+
+
+ Entity not available: [[_config.entity]]
+
+
+ `;
+ }
+
+ static get properties() {
+ return {
+ hass: {
+ type: Object,
+ },
+ _config: Object,
+ _stateObj: {
+ type: Object,
+ computed: "_computeStateObj(hass.states, _config.entity)",
+ },
+ _value: {
+ type: String,
+ value: "",
+ },
+ };
+ }
+
+ getCardSize() {
+ return 4;
+ }
+
+ setConfig(config) {
+ if (
+ !config ||
+ !config.entity ||
+ config.entity.split(".")[0] !== "alarm_control_panel"
+ ) {
+ throw new Error("Invalid card configuration");
+ }
+
+ const defaults = {
+ states: ["arm_away", "arm_home"],
+ };
+
+ this._config = { ...defaults, ...config };
+ this._icons = Icons;
+ }
+
+ _computeStateObj(states, entityId) {
+ return states && entityId in states ? states[entityId] : null;
+ }
+
+ _computeHeader(localize, stateObj) {
+ if (!stateObj) return "";
+ return this._config.title
+ ? this._config.title
+ : this._label(localize, stateObj.state);
+ }
+
+ _computeIcon(stateObj) {
+ return this._icons[stateObj.state] || "hass:shield-outline";
+ }
+
+ _label(localize, state) {
+ return (
+ localize(`state.alarm_control_panel.${state}`) ||
+ localize(`ui.card.alarm_control_panel.${state}`)
+ );
+ }
+
+ _stateIconLabel(state) {
+ const stateLabel = state.split("_").pop();
+ return stateLabel === "disarmed" || stateLabel === "triggered"
+ ? ""
+ : stateLabel;
+ }
+
+ _showActionToggle(state) {
+ return state === "disarmed";
+ }
+
+ _computeClassName(stateObj) {
+ if (!stateObj) return "not-found";
+ return "";
+ }
+
+ _handlePadClick(e) {
+ const val = e.target.getAttribute("value");
+ this._value = val === "clear" ? "" : this._value + val;
+ }
+
+ _handleActionClick(e) {
+ this.hass.callService("alarm_control_panel", "alarm_" + e.target.id, {
+ entity_id: this._stateObj.entity_id,
+ code: this._value,
+ });
+ this._value = "";
+ }
+}
+
+customElements.define("hui-alarm-panel-card", HuiAlarmPanelCard);
diff --git a/src/panels/lovelace/common/create-card-element.js b/src/panels/lovelace/common/create-card-element.js
index ea76238289..7422f9187b 100644
--- a/src/panels/lovelace/common/create-card-element.js
+++ b/src/panels/lovelace/common/create-card-element.js
@@ -1,5 +1,6 @@
import { fireEvent } from "../../../common/dom/fire_event.js";
+import "../cards/hui-alarm-panel-card.js";
import "../cards/hui-conditional-card.js";
import "../cards/hui-entities-card.js";
import "../cards/hui-entity-filter-card.js";
@@ -24,6 +25,7 @@ import "../cards/hui-gauge-card.js";
import createErrorCardConfig from "./create-error-card-config.js";
const CARD_TYPES = new Set([
+ "alarm-panel",
"conditional",
"entities",
"entity-filter",