forked from dresden-elektronik/deconz-rest-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresource.h
190 lines (169 loc) · 5.23 KB
/
resource.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#ifndef RESOURCE_H
#define RESOURCE_H
#include <QDateTime>
#include <vector>
class QString;
class QVariant;
enum ApiDataType
{
DataTypeUnknown,
DataTypeBool,
DataTypeUInt8,
DataTypeUInt16,
DataTypeUInt32,
DataTypeInt8,
DataTypeInt16,
DataTypeInt32,
DataTypeReal,
DataTypeString,
DataTypeTime,
DataTypeTimePattern
};
// resource prefixes: /lights, /sensors, ...
extern const char *RSensors;
extern const char *RLights;
extern const char *RGroups;
extern const char *RConfig;
// resource events
extern const char *REventAdded;
extern const char *REventDeleted;
extern const char *REventValidGroup;
extern const char *REventCheckGroupAnyOn;
// resouce suffixes: state/buttonevent, config/on, ...
extern const char *RInvalidSuffix;
extern const char *RAttrName;
extern const char *RAttrModelId;
extern const char *RAttrType;
extern const char *RAttrClass;
extern const char *RAttrUniqueId;
extern const char *RStateAlert;
extern const char *RStateAllOn;
extern const char *RStateAnyOn;
extern const char *RStateBri;
extern const char *RStateButtonEvent;
extern const char *RStateColorMode;
extern const char *RStateCt;
extern const char *RStateDark;
extern const char *RStateDaylight;
extern const char *RStateEffect;
extern const char *RStateFlag;
extern const char *RStateHue;
extern const char *RStateHumidity;
extern const char *RStateLastUpdated;
extern const char *RStateLightLevel;
extern const char *RStateLux;
extern const char *RStateOn;
extern const char *RStateOpen;
extern const char *RStatePresence;
extern const char *RStatePressure;
extern const char *RStateReachable;
extern const char *RStateSat;
extern const char *RStateStatus;
extern const char *RStateTemperature;
extern const char *RStateX;
extern const char *RStateY;
extern const char *RConfigAlert;
extern const char *RConfigBattery;
extern const char *RConfigColorCapabilities;
extern const char *RConfigCtMin;
extern const char *RConfigCtMax;
extern const char *RConfigConfigured;
extern const char *RConfigDuration;
extern const char *RConfigGroup;
extern const char *RConfigLat;
extern const char *RConfigLedIndication;
extern const char *RConfigLocalTime;
extern const char *RConfigLong;
extern const char *RConfigOn;
extern const char *RConfigPending;
extern const char *RConfigReachable;
extern const char *RConfigSensitivity;
extern const char *RConfigSensitivityMax;
extern const char *RConfigSunriseOffset;
extern const char *RConfigSunsetOffset;
extern const char *RConfigTholdDark;
extern const char *RConfigTholdOffset;
extern const char *RConfigUrl;
extern const char *RConfigUsertest;
#define R_ALERT_DEFAULT QVariant(QLatin1String("none"))
#define R_SENSITIVITY_MAX_DEFAULT 2
#define R_THOLDDARK_DEFAULT 12000
#define R_THOLDOFFSET_DEFAULT 7000
#define R_PENDING_DURATION (1 << 0)
#define R_PENDING_LEDINDICATION (1 << 1)
#define R_PENDING_SENSITIVITY (1 << 2)
#define R_PENDING_USERTEST (1 << 3)
class ResourceItemDescriptor
{
public:
ResourceItemDescriptor() :
type(DataTypeUnknown),
suffix(RInvalidSuffix),
validMin(0),
validMax(0) { }
ResourceItemDescriptor(ApiDataType t, const char *s, int min = 0, int max = 0) :
type(t),
suffix(s),
validMin(min),
validMax(max) { }
bool isValid() const { return (type != DataTypeUnknown && suffix); }
ApiDataType type;
const char *suffix;
int validMin;
int validMax;
};
class ResourceItem
{
public:
ResourceItem(const ResourceItem &other);
ResourceItem(const ResourceItemDescriptor &rid);
ResourceItem &operator=(const ResourceItem &other);
~ResourceItem();
const QString &toString() const;
qint64 toNumber() const;
qint64 toNumberPrevious() const;
bool toBool() const;
QVariant toVariant() const;
bool setValue(const QString &val);
bool setValue(qint64 val);
bool setValue(const QVariant &val);
const ResourceItemDescriptor &descriptor() const;
const QDateTime &lastSet() const;
const QDateTime &lastChanged() const;
void setTimeStamps(const QDateTime &t);
void inRule(int ruleHandle);
const std::vector<int> rulesInvolved() const;
private:
ResourceItem() :
m_num(-1), m_str(0) {}
qint64 m_num;
qint64 m_numPrev;
QString *m_str;
ResourceItemDescriptor m_rid;
QDateTime m_lastSet;
QDateTime m_lastChanged;
std::vector<int> m_rulesInvolved; // the rules a resource item is trigger
};
class Resource
{
public:
Resource(const char *prefix);
const char *prefix() const;
ResourceItem *addItem(ApiDataType type, const char *suffix);
ResourceItem *item(const char *suffix);
const ResourceItem *item(const char *suffix) const;
bool toBool(const char *suffix) const;
qint64 toNumber(const char *suffix) const;
const QString &toString(const char *suffix) const;
int itemCount() const;
ResourceItem *itemForIndex(size_t idx);
const ResourceItem *itemForIndex(size_t idx) const;
private:
Resource() {}
const char *m_prefix;
std::vector<ResourceItem> m_rItems;
};
void initResourceDescriptors();
const char *getResourcePrefix(const QString &str);
bool getResourceItemDescriptor(const QString &str, ResourceItemDescriptor &descr);
#endif // RESOURCE_H