Skip to content
This repository was archived by the owner on May 6, 2021. It is now read-only.

Commit fb1f5fd

Browse files
author
Tim Niggemann
committed
Fixed QString string formatting, added safety check in case the connection to the bridge might be lost.
1 parent 4d0a29a commit fb1f5fd

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

libsrc/leddevice/LedDevicePhilipsHue.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ int LedDevicePhilipsHue::write(const std::vector<ColorRgb> & ledValues) {
3232
saveStates((unsigned int) ledValues.size());
3333
switchOn((unsigned int) ledValues.size());
3434
}
35+
// If there are less states saved than colors given, then maybe something went wrong before.
36+
if (lamps.size() != ledValues.size()) {
37+
restoreStates();
38+
return 0;
39+
}
3540
// Iterate through colors and set light states.
3641
unsigned int idx = 0;
3742
for (const ColorRgb& color : ledValues) {
@@ -51,7 +56,7 @@ int LedDevicePhilipsHue::write(const std::vector<ColorRgb> & ledValues) {
5156
}
5257
// Send adjust color and brightness command in JSON format.
5358
put(getStateRoute(lamp.id),
54-
QString("{\"xy\": [%1, %2], \"bri\": %1}").arg(xy.x).arg(xy.y).arg(qRound(xy.bri * 255.0f)));
59+
QString("{\"xy\": [%1, %2], \"bri\": %3}").arg(xy.x).arg(xy.y).arg(qRound(xy.bri * 255.0f)));
5560
// Remember written color.
5661
lamp.color = xy;
5762
}

0 commit comments

Comments
 (0)