-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlarmTile.tsx
More file actions
52 lines (46 loc) · 1.17 KB
/
Copy pathAlarmTile.tsx
File metadata and controls
52 lines (46 loc) · 1.17 KB
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
import React from "react";
import Tile, { TileProps } from "./Tile";
import AlarmModal, { AlarmModalProps } from "../modals/AlarmModal";
const ARMED_STATES = new Set(["armed_home", "armed_away", "armed_night"]);
type AlarmTileProps = TileProps & {
entityId: string;
};
export default class AlarmTile extends Tile<AlarmTileProps> {
onTouch = async () => {
const { state } = this.getEntity(this.props.entityId);
if (ARMED_STATES.has(state)) {
await this.callService(
"alarm_control_panel",
"alarm_disarm",
{
entity_id: this.props.entityId,
},
{
[this.props.entityId]: {
state: "disarmed",
},
}
);
} else {
this.openModal();
}
};
renderModal(params: AlarmModalProps) {
return <AlarmModal {...params} />;
}
getDefaultIcon() {
const { state } = this.getEntity(this.props.entityId);
switch (state) {
case "armed_home":
case "armed_away":
case "armed_night":
return "bell";
case "triggered":
return "bell-ring";
case "disarmed":
return "bell-off";
default:
return "bell";
}
}
}