-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource.h
277 lines (254 loc) · 8.79 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#ifndef RESOURCE_H
#define RESOURCE_H
#include <QDateTime>
#include <vector>
class QString;
class QVariant;
enum ApiDataType
{
DataTypeUnknown,
DataTypeBool,
DataTypeUInt8,
DataTypeUInt16,
DataTypeUInt32,
DataTypeUInt64,
DataTypeInt8,
DataTypeInt16,
DataTypeInt32,
DataTypeInt64,
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 *RAttrManufacturerName;
extern const char *RAttrModelId;
extern const char *RAttrType;
extern const char *RAttrClass;
extern const char *RAttrUniqueId;
extern const char *RAttrSwVersion;
extern const char *RAttrLastAnnounce;
extern const char *RAttrLastSeen;
extern const char *RActionScene;
extern const char *RStateAlarm;
extern const char *RStateAlert;
extern const char *RStateAllOn;
extern const char *RStateAnyOn;
extern const char *RStateBattery;
extern const char *RStateBri;
extern const char *RStateButtonEvent;
extern const char *RStateCarbonMonoxide;
extern const char *RStateColorMode;
extern const char *RStateConsumption;
extern const char *RStateCurrent;
extern const char *RStateCt;
extern const char *RStateDark;
extern const char *RStateDaylight;
extern const char *RStateEco2;
extern const char *RStateEffect;
extern const char *RStateEventDuration;
extern const char *RStateFire;
extern const char *RStateFlag;
extern const char *RStateGesture;
extern const char *RStateHue;
extern const char *RStateHumidity;
extern const char *RStateLastUpdated;
extern const char *RStateLift;
extern const char *RStateLightLevel;
extern const char *RStateLowBattery;
extern const char *RStateLocaltime;
extern const char *RStateLux;
extern const char *RStateOn;
extern const char *RStateOpen;
extern const char *RStateOrientationX;
extern const char *RStateOrientationY;
extern const char *RStateOrientationZ;
extern const char *RStatePresence;
extern const char *RStatePressure;
extern const char *RStatePower;
extern const char *RStateReachable;
extern const char *RStateSat;
extern const char *RStateSpectralX;
extern const char *RStateSpectralY;
extern const char *RStateSpectralZ;
extern const char *RStateSpeed;
extern const char *RStateStatus;
extern const char *RStateSunrise;
extern const char *RStateSunset;
extern const char *RStateTampered;
extern const char *RStateTemperature;
extern const char *RStateTilt;
extern const char *RStateTiltAngle;
extern const char *RStateValve;
extern const char *RStateVibration;
extern const char *RStateVibrationStrength;
extern const char *RStateVoc;
extern const char *RStateVoltage;
extern const char *RStateWater;
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 *RConfigDelay;
extern const char *RConfigDisplayFlipped;
extern const char *RConfigDuration;
extern const char *RConfigGroup;
extern const char *RConfigHeatSetpoint;
extern const char *RConfigHostFlags;
extern const char *RConfigId;
extern const char *RConfigLat;
extern const char *RConfigLedIndication;
extern const char *RConfigLocalTime;
extern const char *RConfigLocked;
extern const char *RConfigLong;
extern const char *RConfigLevelMin;
extern const char *RConfigMode;
extern const char *RConfigOffset;
extern const char *RConfigOn;
extern const char *RConfigPending;
extern const char *RConfigPowerup;
extern const char *RConfigPowerOnCt;
extern const char *RConfigPowerOnLevel;
extern const char *RConfigReachable;
extern const char *RConfigScheduler;
extern const char *RConfigSchedulerOn;
extern const char *RConfigSensitivity;
extern const char *RConfigSensitivityMax;
extern const char *RConfigSunriseOffset;
extern const char *RConfigSunsetOffset;
extern const char *RConfigTemperature;
extern const char *RConfigTholdDark;
extern const char *RConfigTholdOffset;
extern const char *RConfigUrl;
extern const char *RConfigUsertest;
extern const char *RConfigWindowCoveringType;
extern const char *RConfigUbisysJ1Mode;
extern const char *RConfigUbisysJ1WindowCoveringType;
extern const char *RConfigUbisysJ1ConfigurationAndStatus;
extern const char *RConfigUbisysJ1InstalledOpenLimitLift;
extern const char *RConfigUbisysJ1InstalledClosedLimitLift;
extern const char *RConfigUbisysJ1InstalledOpenLimitTilt;
extern const char *RConfigUbisysJ1InstalledClosedLimitTilt;
extern const char *RConfigUbisysJ1TurnaroundGuardTime;
extern const char *RConfigUbisysJ1LiftToTiltTransitionSteps;
extern const char *RConfigUbisysJ1TotalSteps;
extern const char *RConfigUbisysJ1LiftToTiltTransitionSteps2;
extern const char *RConfigUbisysJ1TotalSteps2;
extern const char *RConfigUbisysJ1AdditionalSteps;
extern const char *RConfigUbisysJ1InactivePowerThreshold;
extern const char *RConfigUbisysJ1StartupSteps;
#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_DELAY (1 << 0)
#define R_PENDING_LEDINDICATION (1 << 1)
#define R_PENDING_SENSITIVITY (1 << 2)
#define R_PENDING_USERTEST (1 << 3)
#define R_PENDING_WRITE_CIE_ADDRESS (1 << 4)
#define R_PENDING_ENROLL_RESPONSE (1 << 5)
#define R_PENDING_WRITE_POLL_CHECKIN_INTERVAL (1 << 6)
#define R_PENDING_SET_LONG_POLL_INTERVAL (1 << 7)
// after device announce is received lights can be brought into a defined state
// this might be useful for powerloss and OTA updates or simply providing a default power on configuration
#define R_POWERUP_RESTORE (1 << 0) // restore last known on/off and brightness state
#define R_POWERUP_RESTORE_AT_DAYLIGHT (1 << 1) // restore at daylight
#define R_POWERUP_RESTORE_AT_NO_DAYLIGHT (1 << 2) // restore when no daylight
class ResourceItemDescriptor
{
public:
ResourceItemDescriptor() :
type(DataTypeUnknown),
suffix(RInvalidSuffix),
validMin(0),
validMax(0) { }
ResourceItemDescriptor(ApiDataType t, const char *s, qint64 min = 0, qint64 max = 0) :
type(t),
suffix(s),
validMin(min),
validMax(max) { }
bool isValid() const { return (type != DataTypeUnknown && suffix); }
ApiDataType type;
const char *suffix;
qint64 validMin;
qint64 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;
bool isPublic() const;
void setIsPublic(bool isPublic);
private:
ResourceItem() = delete;
bool m_isPublic = true;
qint64 m_num = 0;
qint64 m_numPrev = 0;
QString *m_str = nullptr;
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);
~Resource();
Resource(const Resource &other);
Resource &operator=(const Resource &other);
const char *prefix() const;
ResourceItem *addItem(ApiDataType type, const char *suffix);
void removeItem(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;
QDateTime lastStatePush;
private:
Resource() = delete;
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