-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
alarm_control_panel.ts
98 lines (91 loc) · 2.13 KB
/
alarm_control_panel.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import {
mdiAirplane,
mdiHome,
mdiLock,
mdiMoonWaningCrescent,
mdiShield,
mdiShieldOff,
} from "@mdi/js";
import {
HassEntityAttributeBase,
HassEntityBase,
} from "home-assistant-js-websocket";
import { HomeAssistant } from "../types";
export const FORMAT_TEXT = "text";
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,
}
interface AlarmControlPanelEntityAttributes extends HassEntityAttributeBase {
code_format?: "text" | "number";
changed_by?: string | null;
code_arm_required?: boolean;
}
export interface AlarmControlPanelEntity extends HassEntityBase {
attributes: AlarmControlPanelEntityAttributes;
}
export const callAlarmAction = (
hass: HomeAssistant,
entity: string,
action:
| "arm_away"
| "arm_home"
| "arm_night"
| "arm_vacation"
| "arm_custom_bypass"
| "disarm",
code?: string
) => {
hass!.callService("alarm_control_panel", `alarm_${action}`, {
entity_id: entity,
code,
});
};
export type AlarmMode =
| "armed_home"
| "armed_away"
| "armed_night"
| "armed_vacation"
| "armed_custom_bypass"
| "disarmed";
type AlarmConfig = {
service: string;
feature?: AlarmControlPanelEntityFeature;
path: string;
};
export const ALARM_MODES: Record<AlarmMode, AlarmConfig> = {
armed_home: {
feature: AlarmControlPanelEntityFeature.ARM_HOME,
service: "alarm_arm_home",
path: mdiHome,
},
armed_away: {
feature: AlarmControlPanelEntityFeature.ARM_AWAY,
service: "alarm_arm_away",
path: mdiLock,
},
armed_night: {
feature: AlarmControlPanelEntityFeature.ARM_NIGHT,
service: "alarm_arm_night",
path: mdiMoonWaningCrescent,
},
armed_vacation: {
feature: AlarmControlPanelEntityFeature.ARM_VACATION,
service: "alarm_arm_vacation",
path: mdiAirplane,
},
armed_custom_bypass: {
feature: AlarmControlPanelEntityFeature.ARM_CUSTOM_BYPASS,
service: "alarm_arm_custom_bypass",
path: mdiShield,
},
disarmed: {
service: "alarm_disarm",
path: mdiShieldOff,
},
};