Commit b4e3087beb75cd022c31f9ba23ad4177b5b83e00
Committed by
Moritz Wirger
1 parent
74b51fb2
Handle black color conversion and fix transaction with brightness 0 flickering.
Showing
4 changed files
with
25 additions
and
4 deletions
src/ColorUnits.cpp
| ... | ... | @@ -107,6 +107,10 @@ XY ColorGamut::corrected(const XY& xy) const |
| 107 | 107 | |
| 108 | 108 | XYBrightness RGB::toXY() const |
| 109 | 109 | { |
| 110 | + if (r == 0 && g == 0 && b == 0) | |
| 111 | + { | |
| 112 | + return XYBrightness {XY {0.f, 0.f}, 0.f}; | |
| 113 | + } | |
| 110 | 114 | const float red = r / 255.f; |
| 111 | 115 | const float green = g / 255.f; |
| 112 | 116 | const float blue = b / 255.f; | ... | ... |
src/StateTransaction.cpp
| ... | ... | @@ -39,8 +39,8 @@ bool StateTransaction::commit(bool trimRequest) |
| 39 | 39 | // Check this before request is trimmed |
| 40 | 40 | if (!request.count("on")) |
| 41 | 41 | { |
| 42 | - if (!stateJson.value("on", false) | |
| 43 | - && (request.value("bri", 0) != 0 || request.count("effect") || request.count("hue") || request.count("sat") | |
| 42 | + if (!stateJson.value("on", false) && request.value("bri", 254) != 0 | |
| 43 | + && (request.count("bri") || request.count("effect") || request.count("hue") || request.count("sat") | |
| 44 | 44 | || request.count("xy") || request.count("ct"))) |
| 45 | 45 | { |
| 46 | 46 | // Turn on if it was turned off | ... | ... |
test/test_ColorUnits.cpp
| ... | ... | @@ -105,6 +105,13 @@ TEST(RGB, toXY) |
| 105 | 105 | EXPECT_FLOAT_EQ(xy.xy.y, 0.32902291f); |
| 106 | 106 | EXPECT_FLOAT_EQ(xy.brightness, 0.99999905f); |
| 107 | 107 | } |
| 108 | + { | |
| 109 | + const RGB black{ 0,0,0 }; | |
| 110 | + XYBrightness xy = black.toXY(gamut::maxGamut); | |
| 111 | + EXPECT_FLOAT_EQ(xy.xy.x, 0.0f); | |
| 112 | + EXPECT_FLOAT_EQ(xy.xy.y, 0.0f); | |
| 113 | + EXPECT_FLOAT_EQ(xy.brightness, 0.0f); | |
| 114 | + } | |
| 108 | 115 | } |
| 109 | 116 | |
| 110 | 117 | TEST(RGB, fromXY) | ... | ... |
test/test_StateTransaction.cpp
| ... | ... | @@ -154,6 +154,16 @@ TEST(StateTransaction, setBrightness) |
| 154 | 154 | EXPECT_TRUE(StateTransaction(commands, "/path", &state).setBrightness(bri).commit()); |
| 155 | 155 | Mock::VerifyAndClearExpectations(handler.get()); |
| 156 | 156 | } |
| 157 | + // Fixed unexpected on/off flickering | |
| 158 | + { | |
| 159 | + const int hue = 32; | |
| 160 | + nlohmann::json state = {{"on", false}, {"bri", 20}}; | |
| 161 | + nlohmann::json request = { {"hue", hue}, {"bri", 0} }; | |
| 162 | + nlohmann::json response = {{{"success", {{"/path/hue", hue}}}}}; | |
| 163 | + EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | |
| 164 | + EXPECT_TRUE(StateTransaction(commands, "/path", &state).setBrightness(0).setColorHue(hue).commit()); | |
| 165 | + Mock::VerifyAndClearExpectations(handler.get()); | |
| 166 | + } | |
| 157 | 167 | } |
| 158 | 168 | |
| 159 | 169 | TEST(StateTransaction, setColorHue) |
| ... | ... | @@ -303,7 +313,7 @@ TEST(StateTransaction, setColorXY) |
| 303 | 313 | }}, |
| 304 | 314 | {"colormode", "hs"}}; |
| 305 | 315 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 306 | - EXPECT_TRUE(StateTransaction(commands, "/path", &state).setColor(XY{ x, y }).commit()); | |
| 316 | + EXPECT_TRUE(StateTransaction(commands, "/path", &state).setColor(XY {x, y}).commit()); | |
| 307 | 317 | Mock::VerifyAndClearExpectations(handler.get()); |
| 308 | 318 | } |
| 309 | 319 | // No request |
| ... | ... | @@ -318,7 +328,7 @@ TEST(StateTransaction, setColorXY) |
| 318 | 328 | }}, |
| 319 | 329 | {"colormode", "xy"}}; |
| 320 | 330 | EXPECT_CALL(*handler, PUTJson(_, _, getBridgeIp(), getBridgePort())).Times(0); |
| 321 | - EXPECT_TRUE(StateTransaction(commands, "/path", &state).setColor(XY{ x, y }).commit()); | |
| 331 | + EXPECT_TRUE(StateTransaction(commands, "/path", &state).setColor(XY {x, y}).commit()); | |
| 322 | 332 | Mock::VerifyAndClearExpectations(handler.get()); |
| 323 | 333 | } |
| 324 | 334 | } | ... | ... |