forked from dresden-elektronik/deconz-rest-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
group.cpp
286 lines (242 loc) · 6.34 KB
/
group.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
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
278
279
280
281
282
283
284
285
286
/*
* Copyright (c) 2016 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.
*
*/
#include "group.h"
#include <QStringList>
/*! Constructor.
*/
Group::Group() :
Resource(RGroups),
m_state(StateNormal),
m_addr(0),
m_id("0"),
m_on(false),
m_colorLoopActive(false)
{
sendTime = QTime::currentTime();
hidden = false;
hueReal = 0;
hue = 0;
sat = 127;
level = 127;
colorX = 0;
colorY = 0;
colorTemperature = 0;
colormode = QLatin1String("hs");
// add common items
addItem(DataTypeString, RAttrName);
addItem(DataTypeBool, RStateAllOn);
addItem(DataTypeBool, RStateAnyOn);
addItem(DataTypeString, RActionScene);
ResourceItem * rtype = addItem(DataTypeString, RAttrType);
rtype->setValue(QString(QLatin1String("LightGroup")));
ResourceItem * rclass = addItem(DataTypeString, RAttrClass);
rclass->setValue(QString(QLatin1String("Other")));
}
/*! Returns the 16 bit group address.
*/
uint16_t Group::address() const
{
return m_addr;
}
/*! Sets the 16 bit group address.
\param address the 16 bit group address (ZigBee level)
*/
void Group::setAddress(uint16_t address)
{
m_addr = address;
m_id = QString::number(address);
}
/*! Returns the group identifier. */
const QString &Group::id() const
{
return m_id;
}
/*! Returns the group name.
*/
const QString &Group::name() const
{
return item(RAttrName)->toString();
}
/*! Sets the group name.
\param name the group name
*/
void Group::setName(const QString &name)
{
ResourceItem *it = item(RAttrName);
it->setValue(name);
}
/*! Returns the group state.
*/
Group::State Group::state() const
{
return m_state;
}
/*! Sets the group state.
\param state the group state
*/
void Group::setState(State state)
{
m_state = state;
}
/*! Returns true if the group is on. */
bool Group::isOn() const
{
return m_on;
}
/*! Sets the group on state.
\param on whereever the group is on or off
*/
void Group::setIsOn(bool on)
{
m_on = on;
}
/*! Sets the group color loop active state.
\param colorLoopActive whereever the color loop is active
*/
void Group::setColorLoopActive(bool colorLoopActive)
{
m_colorLoopActive = colorLoopActive;
}
/*! Returns true if the color loop is active. */
bool Group::isColorLoopActive() const
{
return m_colorLoopActive;
}
/*! multiDeviceIds to string. */
const QString Group::midsToString() const
{
QString result = "";
std::vector<QString>::const_iterator i = m_multiDeviceIds.begin();
std::vector<QString>::const_iterator end = m_multiDeviceIds.end();
for (;i != end; ++i)
{
result.append(*i);
if (i != end-1)
{
result.append(QLatin1String(","));
}
}
return result;
}
/*! multiDeviceIds String to vector. */
void Group::setMidsFromString(const QString &mids)
{
QStringList list = mids.split(QLatin1String(","), QString::SkipEmptyParts);
QStringList::const_iterator i = list.begin();
QStringList::const_iterator end = list.end();
for (;i != end; ++i)
{
m_multiDeviceIds.push_back(*i);
}
}
/*! deviceMembership to string. */
const QString Group::dmToString() const
{
QString result(QLatin1String(""));
std::vector<QString>::const_iterator i = m_deviceMemberships.begin();
std::vector<QString>::const_iterator end = m_deviceMemberships.end();
for (;i != end; ++i)
{
result.append(*i);
if (i != end-1)
{
result.append(",");
}
}
return result;
}
/*! deviceMembership String to vector. */
void Group::setDmFromString(const QString &deviceIds)
{
QStringList list = deviceIds.split(QLatin1String(","), QString::SkipEmptyParts);
QStringList::const_iterator i = list.begin();
QStringList::const_iterator end = list.end();
for (;i != end; ++i)
{
m_deviceMemberships.push_back(*i);
}
}
/*! lightsequence to string. */
const QString Group::lightsequenceToString() const
{
QString result(QLatin1String(""));
std::vector<QString>::const_iterator i = m_lightsequence.begin();
std::vector<QString>::const_iterator end = m_lightsequence.end();
for (;i != end; ++i)
{
result.append(*i);
if (i != end-1)
{
result.append(QLatin1String(","));
}
}
return result;
}
/*! lightsequence String to vector. */
void Group::setLightsequenceFromString(const QString &lightsequence)
{
QStringList list = lightsequence.split(QLatin1String(","), QString::SkipEmptyParts);
QStringList::const_iterator i = list.begin();
QStringList::const_iterator end = list.end();
for (;i != end; ++i)
{
m_lightsequence.push_back(*i);
}
}
/*! Returns the scene for a given \p sceneId or 0 if not present. */
Scene *Group::getScene(quint8 sceneId)
{
std::vector<Scene>::iterator i = scenes.begin();
std::vector<Scene>::iterator end = scenes.end();
for (; i != end; ++i)
{
if (i->id == sceneId && i->state == Scene::StateNormal)
{
return &*i;
}
}
return 0;
}
/*! Returns true if device with \p id was added to the group. */
bool Group::addDeviceMembership(const QString &id)
{
if (std::find(m_deviceMemberships.begin(), m_deviceMemberships.end(), id) == m_deviceMemberships.end())
{
m_deviceMemberships.push_back(id);
return true;
}
return false;
}
/*! Returns true if device with \p id was removed from the group. */
bool Group::removeDeviceMembership(const QString &id)
{
std::vector<QString>::iterator i = std::find(m_deviceMemberships.begin(), m_deviceMemberships.end(), id);
if (i != m_deviceMemberships.end())
{
*i = m_deviceMemberships.back();
m_deviceMemberships.pop_back();
return true;
}
return false;
}
/*! Returns true if device with \p id controls the group. */
bool Group::deviceIsMember(const QString &id) const
{
if (std::find(m_deviceMemberships.begin(), m_deviceMemberships.end(), id) == m_deviceMemberships.end())
{
return false;
}
return true;
}
/*! Returns true if group is controlled by devices. */
bool Group::hasDeviceMembers() const
{
return !m_deviceMemberships.empty();
}