forked from dresden-elektronik/deconz-rest-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alarm_system.h
125 lines (97 loc) · 3.51 KB
/
alarm_system.h
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* Copyright (c) 2021 dresden elektronik ingenieurtechnik gmbh.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
* style license a copy of which has been included with this distribution in
* the LICENSE.txt file.
*
*/
#ifndef ALARM_SYSTEM_H
#define ALARM_SYSTEM_H
#include <QObject>
#include <vector>
#include "resource.h"
/*! \class AlarmSystem
This class implements a stateful alarm system. The system is controlled with events from physical devices and the REST API.
A general overview can be found at https://dresden-elektronik.github.io/deconz-rest-doc/endpoints/alarmsystems
The state machine mimics a typical alarm system, similar to implementations in home automation systems.
https://www.npmjs.com/package/homebridge-alarm-panel
https://www.home-assistant.io/integrations/manual
There are four target states:
disarmed
armed_away
armed_stay
armed_night
A: alarm system id
M: alarm mask
0000 0001 Away
0000 0010 Stay
0000 0100 Night
RConfigAlarmSystemId: uint32 0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 AAAA AAAA
REventDeviceAlarm uint32 0000 0000 0000 0000 MMMM MMMM AAAA AAAA
*/
#define AS_ARM_MASK_ARMED_AWAY 0x0100
#define AS_ARM_MASK_ARMED_STAY 0x0200
#define AS_ARM_MASK_ARMED_NIGHT 0x0400
class Event;
class EventEmitter;
class AS_DeviceTable;
class AlarmSystemPrivate;
enum AS_ArmMode
{
AS_ArmModeDisarmed = 0,
AS_ArmModeArmedStay = 1,
AS_ArmModeArmedNight = 2,
AS_ArmModeArmedAway = 3,
AS_ArmModeMax
};
using AlarmSystemId = quint32;
class AlarmSystem : public QObject,
public Resource
{
Q_OBJECT
public:
AlarmSystem(AlarmSystemId id, EventEmitter *eventEmitter, AS_DeviceTable *devTable, QObject *parent = nullptr);
~AlarmSystem();
void handleEvent(const Event &event);
void didSetValue(ResourceItem *i) override;
bool isValidCode(const QString &code, quint64 srcExtAddress);
AlarmSystemId id() const;
const QString &idString() const;
quint8 iasAcePanelStatus() const;
uint secondsRemaining() const;
QLatin1String armStateString() const;
AS_ArmMode targetArmMode() const;
bool setTargetArmMode(AS_ArmMode targetArmMode);
bool addDevice(const QString &uniqueId, quint32 flags);
bool removeDevice(const QLatin1String &uniqueId);
const AS_DeviceTable *deviceTable() const;
bool setCode(int index, const QString &code);
void start();
Q_SIGNALS:
void eventNotify(const Event&);
private Q_SLOTS:
void timerFired();
private:
AlarmSystemPrivate *d = nullptr;
};
/*! \class AlarmSystems
RAII wrapper to hold \c AlarmSystem objects.
*/
class AlarmSystems
{
public:
AlarmSystems();
~AlarmSystems();
std::vector<AlarmSystem*> alarmSystems;
};
void DB_LoadAlarmSystems(AlarmSystems &alarmSystems, AS_DeviceTable *devTable, EventEmitter *eventEmitter);
void AS_InitDefaultAlarmSystem(AlarmSystems &alarmSystems, AS_DeviceTable *devTable, EventEmitter *eventEmitter);
QLatin1String AS_ArmModeToString(AS_ArmMode armMode);
AS_ArmMode AS_ArmModeFromString(const QString &armMode);
AlarmSystem *AS_GetAlarmSystemForDevice(quint64 extAddress, AlarmSystems &alarmSystems);
const AlarmSystem *AS_GetAlarmSystem(AlarmSystemId alarmSystemId, const AlarmSystems &alarmSystems);
AlarmSystem *AS_GetAlarmSystem(AlarmSystemId alarmSystemId, AlarmSystems &alarmSystems);
#endif // ALARM_SYSTEM_H