@@ -133,9 +133,9 @@ CiColor PhilipsHueLamp::rgbToCiColor(float red, float green, float blue) {
133133}
134134
135135LedDevicePhilipsHue::LedDevicePhilipsHue (const std::string& output, const std::string& username, bool switchOffOnBlack,
136- int transitiontime) :
136+ int transitiontime, std::vector< unsigned int > lightIds ) :
137137 host(output.c_str()), username(username.c_str()), switchOffOnBlack(switchOffOnBlack), transitiontime(
138- transitiontime) {
138+ transitiontime), lightIds(lightIds) {
139139 http = new QHttp (host);
140140 timer.setInterval (3000 );
141141 timer.setSingleShot (true );
@@ -251,10 +251,17 @@ void LedDevicePhilipsHue::saveStates(unsigned int nLights) {
251251 // Use json parser to parse reponse.
252252 Json::Reader reader;
253253 Json::FastWriter writer;
254+ // Create light ids if none supplied by the user.
255+ if (lightIds.size () != nLights) {
256+ lightIds.clear ();
257+ for (unsigned int i = 0 ; i < nLights; i++) {
258+ lightIds.push_back (i + 1 );
259+ }
260+ }
254261 // Iterate lights.
255262 for (unsigned int i = 0 ; i < nLights; i++) {
256263 // Read the response.
257- QByteArray response = get (getRoute (i + 1 ));
264+ QByteArray response = get (getRoute (lightIds. at (i) ));
258265 // Parse JSON.
259266 Json::Value json;
260267 if (!reader.parse (QString (response).toStdString (), json)) {
@@ -272,7 +279,7 @@ void LedDevicePhilipsHue::saveStates(unsigned int nLights) {
272279 QString modelId = QString (writer.write (json[" modelid" ]).c_str ()).trimmed ().replace (" \" " , " " );
273280 QString originalState = QString (writer.write (state).c_str ()).trimmed ();
274281 // Save state object.
275- lamps.push_back (PhilipsHueLamp (i + 1 , originalState, modelId));
282+ lamps.push_back (PhilipsHueLamp (lightIds. at (i) , originalState, modelId));
276283 }
277284}
278285
0 commit comments