forked from dresden-elektronik/deconz-rest-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
appliances.cpp
66 lines (57 loc) · 2.27 KB
/
appliances.cpp
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
#include "de_web_plugin.h"
#include "de_web_plugin_private.h"
// server receive
#define CMD_GET_ALERTS 0x00
// server send
#define CMD_GET_ALERTS_RESPONSE 0x00
#define CMD_ALERTS_NOTIFICATION 0x01
#define CMD_EVENT_NOTIFICATION 0x02
// read flags
#define ALERTS_ALERT (1 << 12)
/*! Handle packets related to the Appliance Alerts and Events cluster.
\param ind the APS level data indication containing the ZCL packet
\param zclFrame the actual ZCL frame which holds the Appliance Alerts and Events server command
*/
void DeRestPluginPrivate::handleApplianceAlertClusterIndication(const deCONZ::ApsDataIndication &ind, deCONZ::ZclFrame &zclFrame)
{
QDataStream stream(zclFrame.payload());
stream.setByteOrder(QDataStream::LittleEndian);
if (!(zclFrame.frameControl() & deCONZ::ZclFCDirectionServerToClient))
{
return;
}
if (zclFrame.commandId() == CMD_ALERTS_NOTIFICATION && zclFrame.isClusterCommand())
{
quint8 alertsCount; // Count is just 4 Bits but doesn't matter right now
quint16 alertsStructure; // 24 Bit long, but 16 suffice
stream >> alertsCount;
stream >> alertsStructure;
// Specific to leakSMART water sensor V2
// Should be more generic
SensorFingerprint fp;
fp.endpoint = 0x01;
fp.deviceId = 0x0302;
fp.profileId = 0x0104;
fp.inClusters.push_back(POWER_CONFIGURATION_CLUSTER_ID);
fp.inClusters.push_back(APPLIANCE_EVENTS_AND_ALERTS_CLUSTER_ID);
Sensor *sensor = getSensorNodeForFingerPrint(ind.srcAddress().ext(), fp, "ZHAWater");
ResourceItem *item = sensor ? sensor->item(RStateWater) : nullptr;
if (sensor && item)
{
if (alertsStructure & ALERTS_ALERT)
{
item->setValue(true);
}
else
{
item->setValue(false);
}
sensor->updateStateTimestamp();
enqueueEvent(Event(RSensors, RStateWater, sensor->id(), item));
enqueueEvent(Event(RSensors, RStateLastUpdated, sensor->id()));
sensor->setNeedSaveDatabase(true);
queSaveDb(DB_SENSORS, DB_SHORT_SAVE_DELAY);
updateSensorEtag(&*sensor);
}
}
}