Commit 9339e952f7fc437796d7e27c88bb68111e6286d7
Committed by
Moritz Wirger
1 parent
fd4a6765
Make StateTransaction update the cached state.
This makes the state of a light consistant without needing to refresh more often.
Showing
6 changed files
with
128 additions
and
115 deletions
include/hueplusplus/StateTransaction.h
| ... | ... | @@ -39,15 +39,18 @@ namespace hueplusplus |
| 39 | 39 | //! \code |
| 40 | 40 | //! light.transaction().setOn(true).setBrightness(29).setColorHue(3000).setColorSaturation(128).commit(); |
| 41 | 41 | //! \endcode |
| 42 | +//! \note The transaction has an internal reference to the light state. | |
| 43 | +//! You must not cause a refresh of the state between creating and committing the transaction | |
| 44 | +//! (e.g. non-const getters/setters), because that invalidates the reference. | |
| 42 | 45 | class StateTransaction |
| 43 | 46 | { |
| 44 | 47 | public: |
| 45 | 48 | //! \brief Creates a StateTransaction to a group or light state |
| 46 | 49 | //! \param commands HueCommandAPI for making requests |
| 47 | 50 | //! \param path Path to which the final PUT request is made (without username) |
| 48 | - //! \param currentState JSON object with the current state to check whether changes are needed. | |
| 49 | - //! Pass an empty object to always include all requests (for groups, because individual lights might be different). | |
| 50 | - StateTransaction(const HueCommandAPI& commands, const std::string& path, const nlohmann::json& currentState); | |
| 51 | + //! \param currentState Optional, the current state to check whether changes are needed. | |
| 52 | + //! Pass nullptr to always include all requests (for groups, because individual lights might be different). | |
| 53 | + StateTransaction(const HueCommandAPI& commands, const std::string& path, nlohmann::json* currentState); | |
| 51 | 54 | |
| 52 | 55 | //! \brief Deleted copy constructor, do not store StateTransaction in a variable. |
| 53 | 56 | StateTransaction(const StateTransaction&) = delete; |
| ... | ... | @@ -165,7 +168,7 @@ private: |
| 165 | 168 | private: |
| 166 | 169 | const HueCommandAPI& commands; |
| 167 | 170 | std::string path; |
| 168 | - nlohmann::json state; | |
| 171 | + nlohmann::json* state; | |
| 169 | 172 | nlohmann::json request; |
| 170 | 173 | }; |
| 171 | 174 | ... | ... |
src/Group.cpp
| ... | ... | @@ -142,7 +142,7 @@ StateTransaction Group::transaction() |
| 142 | 142 | { |
| 143 | 143 | // Do not pass state, because it is not the state of ALL lights in the group |
| 144 | 144 | return StateTransaction( |
| 145 | - state.getCommandAPI(), "/groups/" + std::to_string(id) + "/action", nlohmann::json::object()); | |
| 145 | + state.getCommandAPI(), "/groups/" + std::to_string(id) + "/action", nullptr); | |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | void Group::setOn(bool on, uint8_t transition) | ... | ... |
src/HueLight.cpp
| ... | ... | @@ -171,7 +171,7 @@ bool HueLight::alert() |
| 171 | 171 | StateTransaction HueLight::transaction() |
| 172 | 172 | { |
| 173 | 173 | return StateTransaction( |
| 174 | - state.getCommandAPI(), "/lights/" + std::to_string(id) + "/state", state.getValue().at("state")); | |
| 174 | + state.getCommandAPI(), "/lights/" + std::to_string(id) + "/state", &state.getValue().at("state")); | |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | void HueLight::refresh() | ... | ... |
src/StateTransaction.cpp
| ... | ... | @@ -30,12 +30,9 @@ |
| 30 | 30 | |
| 31 | 31 | namespace hueplusplus |
| 32 | 32 | { |
| 33 | -StateTransaction::StateTransaction( | |
| 34 | - const HueCommandAPI& commands, const std::string& path, const nlohmann::json& currentState) | |
| 33 | +StateTransaction::StateTransaction(const HueCommandAPI& commands, const std::string& path, nlohmann::json* currentState) | |
| 35 | 34 | : commands(commands), path(path), state(currentState), request(nlohmann::json::object()) |
| 36 | -{ | |
| 37 | - assert(currentState.is_object()); | |
| 38 | -} | |
| 35 | +{} | |
| 39 | 36 | |
| 40 | 37 | bool StateTransaction::commit(bool trimRequest) && |
| 41 | 38 | { |
| ... | ... | @@ -46,16 +43,17 @@ bool StateTransaction::commit(bool trimRequest) && |
| 46 | 43 | // Empty request or request with only transition makes no sense |
| 47 | 44 | if (!request.empty() && !(request.size() == 1 && request.count("transitiontime"))) |
| 48 | 45 | { |
| 46 | + const nlohmann::json& stateJson = (state != nullptr) ? *state : nlohmann::json::object(); | |
| 49 | 47 | if (!request.count("on")) |
| 50 | 48 | { |
| 51 | - if (!state.value("on", false) | |
| 49 | + if (!stateJson.value("on", false) | |
| 52 | 50 | && (request.value("bri", 0) != 0 || request.count("effect") || request.count("hue") |
| 53 | 51 | || request.count("sat") || request.count("xy") || request.count("ct"))) |
| 54 | 52 | { |
| 55 | 53 | // Turn on if it was turned off |
| 56 | 54 | request["on"] = true; |
| 57 | 55 | } |
| 58 | - else if (request.value("bri", 254) == 0 && state.value("on", true)) | |
| 56 | + else if (request.value("bri", 254) == 0 && stateJson.value("on", true)) | |
| 59 | 57 | { |
| 60 | 58 | // Turn off if brightness is 0 |
| 61 | 59 | request["on"] = false; |
| ... | ... | @@ -63,7 +61,23 @@ bool StateTransaction::commit(bool trimRequest) && |
| 63 | 61 | } |
| 64 | 62 | |
| 65 | 63 | nlohmann::json reply = commands.PUTRequest(path, request, CURRENT_FILE_INFO); |
| 66 | - return utils::validatePUTReply(path, request, reply); | |
| 64 | + if (utils::validatePUTReply(path, request, reply)) | |
| 65 | + { | |
| 66 | + if (state != nullptr) | |
| 67 | + { | |
| 68 | + // Apply changes to state | |
| 69 | + for (auto it = request.begin(); it != request.end(); ++it) | |
| 70 | + { | |
| 71 | + if (it.key() == "transitiontime") | |
| 72 | + { | |
| 73 | + continue; | |
| 74 | + } | |
| 75 | + (*state)[it.key()] = it.value(); | |
| 76 | + } | |
| 77 | + } | |
| 78 | + return true; | |
| 79 | + } | |
| 80 | + return false; | |
| 67 | 81 | } |
| 68 | 82 | return true; |
| 69 | 83 | } |
| ... | ... | @@ -108,9 +122,9 @@ StateTransaction&& StateTransaction::setColorXY(float x, float y) && |
| 108 | 122 | return std::move(*this); |
| 109 | 123 | } |
| 110 | 124 | |
| 111 | -StateTransaction&& StateTransaction::setColorXY(const XYBrightness& xy)&& | |
| 125 | +StateTransaction&& StateTransaction::setColorXY(const XYBrightness& xy) && | |
| 112 | 126 | { |
| 113 | - request["xy"] = { xy.xy.x, xy.xy.y }; | |
| 127 | + request["xy"] = {xy.xy.x, xy.xy.y}; | |
| 114 | 128 | request["bri"] = static_cast<int>(std::round(xy.brightness * 255.f)); |
| 115 | 129 | |
| 116 | 130 | return std::move(*this); |
| ... | ... | @@ -189,7 +203,7 @@ void StateTransaction::trimRequest() |
| 189 | 203 | = {{"sat", "hs"}, {"hue", "hs"}, {"xy", "xy"}, {"ct", "ct"}}; |
| 190 | 204 | static const std::set<std::string> otherRemove = {"on", "bri", "effect"}; |
| 191 | 205 | // Skip when there is no state provided (e.g. for groups) |
| 192 | - if (state.empty()) | |
| 206 | + if (!state) | |
| 193 | 207 | { |
| 194 | 208 | return; |
| 195 | 209 | } |
| ... | ... | @@ -199,8 +213,8 @@ void StateTransaction::trimRequest() |
| 199 | 213 | if (colormodeIt != colormodes.end()) |
| 200 | 214 | { |
| 201 | 215 | // Only erase color commands if colormode and value matches |
| 202 | - auto stateIt = state.find(it.key()); | |
| 203 | - if (stateIt != state.end() && state.value("colormode", "") == colormodeIt->second) | |
| 216 | + auto stateIt = state->find(it.key()); | |
| 217 | + if (stateIt != state->end() && state->value("colormode", "") == colormodeIt->second) | |
| 204 | 218 | { |
| 205 | 219 | // Compare xy using float comparison |
| 206 | 220 | if ((!it->is_array() && *stateIt == *it) |
| ... | ... | @@ -214,7 +228,7 @@ void StateTransaction::trimRequest() |
| 214 | 228 | } |
| 215 | 229 | else if (otherRemove.count(it.key())) |
| 216 | 230 | { |
| 217 | - if (state.count(it.key()) && state[it.key()] == *it) | |
| 231 | + if (state->count(it.key()) && (*state)[it.key()] == *it) | |
| 218 | 232 | { |
| 219 | 233 | it = request.erase(it); |
| 220 | 234 | continue; | ... | ... |
test/test_SimpleBrightnessStrategy.cpp
| ... | ... | @@ -55,6 +55,7 @@ TEST(SimpleBrightnessStrategy, setBrightness) |
| 55 | 55 | EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(0, 4, test_light)); |
| 56 | 56 | // Only set brightness, already off |
| 57 | 57 | test_light.getState()["state"]["on"] = false; |
| 58 | + test_light.getState()["state"].erase("bri"); | |
| 58 | 59 | prep_ret = {{{"success", {{"/lights/1/state/bri", 0}}}}}; |
| 59 | 60 | EXPECT_CALL(*handler, PUTJson(statePath, _, getBridgeIp(), getBridgePort())).Times(1).WillOnce(Return(prep_ret)); |
| 60 | 61 | EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(0, 4, test_light)); |
| ... | ... | @@ -71,6 +72,7 @@ TEST(SimpleBrightnessStrategy, setBrightness) |
| 71 | 72 | prep_ret[1]["success"]["/lights/1/state/bri"] = 254; |
| 72 | 73 | EXPECT_CALL(*handler, PUTJson(statePath, _, getBridgeIp(), getBridgePort())).Times(1).WillOnce(Return(prep_ret)); |
| 73 | 74 | test_light.getState()["state"]["on"] = false; |
| 75 | + test_light.getState()["state"]["bri"] = 50; | |
| 74 | 76 | EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(255, 6, test_light)); |
| 75 | 77 | } |
| 76 | 78 | ... | ... |
test/test_StateTransaction.cpp
| ... | ... | @@ -20,9 +20,10 @@ |
| 20 | 20 | along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. |
| 21 | 21 | **/ |
| 22 | 22 | |
| 23 | -#include <gtest/gtest.h> | |
| 24 | 23 | #include <hueplusplus/StateTransaction.h> |
| 25 | 24 | |
| 25 | +#include <gtest/gtest.h> | |
| 26 | + | |
| 26 | 27 | #include "testhelper.h" |
| 27 | 28 | |
| 28 | 29 | #include "mocks/mock_HttpHandler.h" |
| ... | ... | @@ -37,7 +38,7 @@ TEST(StateTransaction, commit) |
| 37 | 38 | const std::string requestPath = "/api/" + getBridgeUsername() + "/path"; |
| 38 | 39 | { |
| 39 | 40 | EXPECT_CALL(*handler, PUTJson(_, _, getBridgeIp(), getBridgePort())).Times(0); |
| 40 | - EXPECT_TRUE(StateTransaction(commands, "/path", nlohmann::json::object()).commit()); | |
| 41 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).commit()); | |
| 41 | 42 | Mock::VerifyAndClearExpectations(handler.get()); |
| 42 | 43 | } |
| 43 | 44 | // Explicit off overrides brightness |
| ... | ... | @@ -45,17 +46,16 @@ TEST(StateTransaction, commit) |
| 45 | 46 | nlohmann::json request = {{"on", false}, {"bri", 100}}; |
| 46 | 47 | nlohmann::json response = {{{"success", {{"/path/on", false}}}}, {{"success", {{"/path/bri", 100}}}}}; |
| 47 | 48 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 48 | - EXPECT_TRUE( | |
| 49 | - StateTransaction(commands, "/path", nlohmann::json::object()).setOn(false).setBrightness(100).commit()); | |
| 49 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).setOn(false).setBrightness(100).commit()); | |
| 50 | 50 | Mock::VerifyAndClearExpectations(handler.get()); |
| 51 | 51 | } |
| 52 | 52 | // Do not trim |
| 53 | 53 | { |
| 54 | 54 | const nlohmann::json request = {{"on", false}, {"bri", 100}}; |
| 55 | - const nlohmann::json state = {{"on", false}, {"bri", 100}}; | |
| 55 | + nlohmann::json state = {{"on", false}, {"bri", 100}}; | |
| 56 | 56 | nlohmann::json response = {{{"success", {{"/path/on", false}}}}, {{"success", {{"/path/bri", 100}}}}}; |
| 57 | 57 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 58 | - EXPECT_TRUE(StateTransaction(commands, "/path", state).setOn(false).setBrightness(100).commit(false)); | |
| 58 | + EXPECT_TRUE(StateTransaction(commands, "/path", &state).setOn(false).setBrightness(100).commit(false)); | |
| 59 | 59 | Mock::VerifyAndClearExpectations(handler.get()); |
| 60 | 60 | } |
| 61 | 61 | } |
| ... | ... | @@ -67,10 +67,8 @@ TEST(StateTransaction, toScheduleCommand) |
| 67 | 67 | const std::string requestPath = "/api/" + getBridgeUsername() + "/path"; |
| 68 | 68 | nlohmann::json request = {{"on", false}, {"bri", 100}}; |
| 69 | 69 | |
| 70 | - ScheduleCommand command = StateTransaction(commands, "/path", nlohmann::json::object()) | |
| 71 | - .setOn(false) | |
| 72 | - .setBrightness(100) | |
| 73 | - .toScheduleCommand(); | |
| 70 | + ScheduleCommand command | |
| 71 | + = StateTransaction(commands, "/path", nullptr).setOn(false).setBrightness(100).toScheduleCommand(); | |
| 74 | 72 | Mock::VerifyAndClearExpectations(handler.get()); |
| 75 | 73 | EXPECT_EQ(ScheduleCommand::Method::put, command.getMethod()); |
| 76 | 74 | EXPECT_EQ(request, command.getBody()); |
| ... | ... | @@ -87,7 +85,7 @@ TEST(StateTransaction, setOn) |
| 87 | 85 | nlohmann::json request = {{"on", true}}; |
| 88 | 86 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}}; |
| 89 | 87 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 90 | - EXPECT_TRUE(StateTransaction(commands, "/path", nlohmann::json::object()).setOn(true).commit()); | |
| 88 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).setOn(true).commit()); | |
| 91 | 89 | Mock::VerifyAndClearExpectations(handler.get()); |
| 92 | 90 | } |
| 93 | 91 | // Set off |
| ... | ... | @@ -95,7 +93,7 @@ TEST(StateTransaction, setOn) |
| 95 | 93 | nlohmann::json request = {{"on", false}}; |
| 96 | 94 | nlohmann::json response = {{{"success", {{"/path/on", false}}}}}; |
| 97 | 95 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 98 | - EXPECT_TRUE(StateTransaction(commands, "/path", nlohmann::json::object()).setOn(false).commit()); | |
| 96 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).setOn(false).commit()); | |
| 99 | 97 | Mock::VerifyAndClearExpectations(handler.get()); |
| 100 | 98 | } |
| 101 | 99 | // Fail |
| ... | ... | @@ -103,13 +101,14 @@ TEST(StateTransaction, setOn) |
| 103 | 101 | nlohmann::json request = {{"on", false}}; |
| 104 | 102 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}}; |
| 105 | 103 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 106 | - EXPECT_FALSE(StateTransaction(commands, "/path", nlohmann::json::object()).setOn(false).commit()); | |
| 104 | + EXPECT_FALSE(StateTransaction(commands, "/path", nullptr).setOn(false).commit()); | |
| 107 | 105 | Mock::VerifyAndClearExpectations(handler.get()); |
| 108 | 106 | } |
| 109 | 107 | // No change requested |
| 110 | 108 | { |
| 109 | + nlohmann::json state = {{"on", false}}; | |
| 111 | 110 | EXPECT_CALL(*handler, PUTJson(_, _, getBridgeIp(), getBridgePort())).Times(0); |
| 112 | - EXPECT_TRUE(StateTransaction(commands, "/path", {{"on", false}}).setOn(false).commit()); | |
| 111 | + EXPECT_TRUE(StateTransaction(commands, "/path", &state).setOn(false).commit()); | |
| 113 | 112 | Mock::VerifyAndClearExpectations(handler.get()); |
| 114 | 113 | } |
| 115 | 114 | } |
| ... | ... | @@ -125,7 +124,7 @@ TEST(StateTransaction, setBrightness) |
| 125 | 124 | nlohmann::json request = {{"on", true}, {"bri", bri}}; |
| 126 | 125 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/bri", bri}}}}}; |
| 127 | 126 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 128 | - EXPECT_TRUE(StateTransaction(commands, "/path", nlohmann::json::object()).setBrightness(bri).commit()); | |
| 127 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).setBrightness(bri).commit()); | |
| 129 | 128 | Mock::VerifyAndClearExpectations(handler.get()); |
| 130 | 129 | } |
| 131 | 130 | // Clamp to 254 |
| ... | ... | @@ -134,7 +133,7 @@ TEST(StateTransaction, setBrightness) |
| 134 | 133 | nlohmann::json request = {{"on", true}, {"bri", bri}}; |
| 135 | 134 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/bri", bri}}}}}; |
| 136 | 135 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 137 | - EXPECT_TRUE(StateTransaction(commands, "/path", nlohmann::json::object()).setBrightness(255).commit()); | |
| 136 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).setBrightness(255).commit()); | |
| 138 | 137 | Mock::VerifyAndClearExpectations(handler.get()); |
| 139 | 138 | } |
| 140 | 139 | // Already off |
| ... | ... | @@ -142,15 +141,17 @@ TEST(StateTransaction, setBrightness) |
| 142 | 141 | const int bri = 0; |
| 143 | 142 | nlohmann::json request = {{"bri", bri}}; |
| 144 | 143 | nlohmann::json response = {{{"success", {{"/path/bri", bri}}}}}; |
| 144 | + nlohmann::json state = {{"on", false}}; | |
| 145 | 145 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 146 | - EXPECT_TRUE(StateTransaction(commands, "/path", {{"on", false}}).setBrightness(bri).commit()); | |
| 146 | + EXPECT_TRUE(StateTransaction(commands, "/path", &state).setBrightness(bri).commit()); | |
| 147 | 147 | Mock::VerifyAndClearExpectations(handler.get()); |
| 148 | 148 | } |
| 149 | 149 | // No change requested |
| 150 | 150 | { |
| 151 | 151 | const int bri = 120; |
| 152 | + nlohmann::json state = {{"on", true}, {"bri", bri}}; | |
| 152 | 153 | EXPECT_CALL(*handler, PUTJson(_, _, getBridgeIp(), getBridgePort())).Times(0); |
| 153 | - EXPECT_TRUE(StateTransaction(commands, "/path", {{"on", true}, {"bri", bri}}).setBrightness(bri).commit()); | |
| 154 | + EXPECT_TRUE(StateTransaction(commands, "/path", &state).setBrightness(bri).commit()); | |
| 154 | 155 | Mock::VerifyAndClearExpectations(handler.get()); |
| 155 | 156 | } |
| 156 | 157 | } |
| ... | ... | @@ -166,7 +167,7 @@ TEST(StateTransaction, setColorHue) |
| 166 | 167 | nlohmann::json request = {{"on", true}, {"hue", hue}}; |
| 167 | 168 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/hue", hue}}}}}; |
| 168 | 169 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 169 | - EXPECT_TRUE(StateTransaction(commands, "/path", nlohmann::json::object()).setColorHue(hue).commit()); | |
| 170 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).setColorHue(hue).commit()); | |
| 170 | 171 | Mock::VerifyAndClearExpectations(handler.get()); |
| 171 | 172 | } |
| 172 | 173 | // Already on |
| ... | ... | @@ -174,8 +175,9 @@ TEST(StateTransaction, setColorHue) |
| 174 | 175 | const int hue = 2159; |
| 175 | 176 | nlohmann::json request = {{"hue", hue}}; |
| 176 | 177 | nlohmann::json response = {{{"success", {{"/path/hue", hue}}}}}; |
| 178 | + nlohmann::json state = {{"on", true}}; | |
| 177 | 179 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 178 | - EXPECT_TRUE(StateTransaction(commands, "/path", {{"on", true}}).setColorHue(hue).commit()); | |
| 180 | + EXPECT_TRUE(StateTransaction(commands, "/path", &state).setColorHue(hue).commit()); | |
| 179 | 181 | Mock::VerifyAndClearExpectations(handler.get()); |
| 180 | 182 | } |
| 181 | 183 | // Wrong colormode |
| ... | ... | @@ -183,19 +185,17 @@ TEST(StateTransaction, setColorHue) |
| 183 | 185 | const int hue = 2159; |
| 184 | 186 | nlohmann::json request = {{"hue", hue}}; |
| 185 | 187 | nlohmann::json response = {{{"success", {{"/path/hue", hue}}}}}; |
| 188 | + nlohmann::json state = {{"on", true}, {"hue", hue}, {"colormode", "ct"}}; | |
| 186 | 189 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 187 | - EXPECT_TRUE(StateTransaction(commands, "/path", {{"on", true}, {"hue", hue}, {"colormode", "ct"}}) | |
| 188 | - .setColorHue(hue) | |
| 189 | - .commit()); | |
| 190 | + EXPECT_TRUE(StateTransaction(commands, "/path", &state).setColorHue(hue).commit()); | |
| 190 | 191 | Mock::VerifyAndClearExpectations(handler.get()); |
| 191 | 192 | } |
| 192 | 193 | // No request |
| 193 | 194 | { |
| 194 | 195 | const int hue = 2159; |
| 196 | + nlohmann::json state = {{"on", true}, {"hue", hue}, {"colormode", "hs"}}; | |
| 195 | 197 | EXPECT_CALL(*handler, PUTJson(_, _, getBridgeIp(), getBridgePort())).Times(0); |
| 196 | - EXPECT_TRUE(StateTransaction(commands, "/path", {{"on", true}, {"hue", hue}, {"colormode", "hs"}}) | |
| 197 | - .setColorHue(hue) | |
| 198 | - .commit()); | |
| 198 | + EXPECT_TRUE(StateTransaction(commands, "/path", &state).setColorHue(hue).commit()); | |
| 199 | 199 | Mock::VerifyAndClearExpectations(handler.get()); |
| 200 | 200 | } |
| 201 | 201 | } |
| ... | ... | @@ -211,7 +211,7 @@ TEST(StateTransaction, setColorSaturation) |
| 211 | 211 | nlohmann::json request = {{"on", true}, {"sat", sat}}; |
| 212 | 212 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/sat", sat}}}}}; |
| 213 | 213 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 214 | - EXPECT_TRUE(StateTransaction(commands, "/path", nlohmann::json::object()).setColorSaturation(sat).commit()); | |
| 214 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).setColorSaturation(sat).commit()); | |
| 215 | 215 | Mock::VerifyAndClearExpectations(handler.get()); |
| 216 | 216 | } |
| 217 | 217 | // Clamp to 254 |
| ... | ... | @@ -220,7 +220,7 @@ TEST(StateTransaction, setColorSaturation) |
| 220 | 220 | nlohmann::json request = {{"on", true}, {"sat", sat}}; |
| 221 | 221 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/sat", sat}}}}}; |
| 222 | 222 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 223 | - EXPECT_TRUE(StateTransaction(commands, "/path", nlohmann::json::object()).setColorSaturation(255).commit()); | |
| 223 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).setColorSaturation(255).commit()); | |
| 224 | 224 | Mock::VerifyAndClearExpectations(handler.get()); |
| 225 | 225 | } |
| 226 | 226 | // Already on |
| ... | ... | @@ -228,8 +228,9 @@ TEST(StateTransaction, setColorSaturation) |
| 228 | 228 | const int sat = 125; |
| 229 | 229 | nlohmann::json request = {{"sat", sat}}; |
| 230 | 230 | nlohmann::json response = {{{"success", {{"/path/sat", sat}}}}}; |
| 231 | + nlohmann::json state = {{"on", true}}; | |
| 231 | 232 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 232 | - EXPECT_TRUE(StateTransaction(commands, "/path", {{"on", true}}).setColorSaturation(sat).commit()); | |
| 233 | + EXPECT_TRUE(StateTransaction(commands, "/path", &state).setColorSaturation(sat).commit()); | |
| 233 | 234 | Mock::VerifyAndClearExpectations(handler.get()); |
| 234 | 235 | } |
| 235 | 236 | // Wrong colormode |
| ... | ... | @@ -237,19 +238,17 @@ TEST(StateTransaction, setColorSaturation) |
| 237 | 238 | const int sat = 125; |
| 238 | 239 | nlohmann::json request = {{"sat", sat}}; |
| 239 | 240 | nlohmann::json response = {{{"success", {{"/path/sat", sat}}}}}; |
| 241 | + nlohmann::json state = {{"on", true}, {"sat", sat}, {"colormode", "ct"}}; | |
| 240 | 242 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 241 | - EXPECT_TRUE(StateTransaction(commands, "/path", {{"on", true}, {"sat", sat}, {"colormode", "ct"}}) | |
| 242 | - .setColorSaturation(sat) | |
| 243 | - .commit()); | |
| 243 | + EXPECT_TRUE(StateTransaction(commands, "/path", &state).setColorSaturation(sat).commit()); | |
| 244 | 244 | Mock::VerifyAndClearExpectations(handler.get()); |
| 245 | 245 | } |
| 246 | 246 | // No request |
| 247 | 247 | { |
| 248 | 248 | const int sat = 125; |
| 249 | + nlohmann::json state = {{"on", true}, {"sat", sat}, {"colormode", "hs"}}; | |
| 249 | 250 | EXPECT_CALL(*handler, PUTJson(_, _, getBridgeIp(), getBridgePort())).Times(0); |
| 250 | - EXPECT_TRUE(StateTransaction(commands, "/path", {{"on", true}, {"sat", sat}, {"colormode", "hs"}}) | |
| 251 | - .setColorSaturation(sat) | |
| 252 | - .commit()); | |
| 251 | + EXPECT_TRUE(StateTransaction(commands, "/path", &state).setColorSaturation(sat).commit()); | |
| 253 | 252 | Mock::VerifyAndClearExpectations(handler.get()); |
| 254 | 253 | } |
| 255 | 254 | } |
| ... | ... | @@ -266,7 +265,7 @@ TEST(StateTransaction, setColorXY) |
| 266 | 265 | nlohmann::json request = {{"on", true}, {"xy", {x, y}}}; |
| 267 | 266 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/xy", {x, y}}}}}}; |
| 268 | 267 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 269 | - EXPECT_TRUE(StateTransaction(commands, "/path", nlohmann::json::object()).setColorXY(x, y).commit()); | |
| 268 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).setColorXY(x, y).commit()); | |
| 270 | 269 | Mock::VerifyAndClearExpectations(handler.get()); |
| 271 | 270 | } |
| 272 | 271 | // Clamp |
| ... | ... | @@ -276,7 +275,7 @@ TEST(StateTransaction, setColorXY) |
| 276 | 275 | nlohmann::json request = {{"on", true}, {"xy", {x, y}}}; |
| 277 | 276 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/xy", {x, y}}}}}}; |
| 278 | 277 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 279 | - EXPECT_TRUE(StateTransaction(commands, "/path", nlohmann::json::object()).setColorXY(2.f, -1.f).commit()); | |
| 278 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).setColorXY(2.f, -1.f).commit()); | |
| 280 | 279 | Mock::VerifyAndClearExpectations(handler.get()); |
| 281 | 280 | } |
| 282 | 281 | // Already on |
| ... | ... | @@ -285,8 +284,9 @@ TEST(StateTransaction, setColorXY) |
| 285 | 284 | const float y = 0.8f; |
| 286 | 285 | nlohmann::json request = {{"xy", {x, y}}}; |
| 287 | 286 | nlohmann::json response = {{{"success", {{"/path/xy", {x, y}}}}}}; |
| 287 | + nlohmann::json state = {{"on", true}}; | |
| 288 | 288 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 289 | - EXPECT_TRUE(StateTransaction(commands, "/path", {{"on", true}}).setColorXY(x, y).commit()); | |
| 289 | + EXPECT_TRUE(StateTransaction(commands, "/path", &state).setColorXY(x, y).commit()); | |
| 290 | 290 | Mock::VerifyAndClearExpectations(handler.get()); |
| 291 | 291 | } |
| 292 | 292 | // Wrong colormode |
| ... | ... | @@ -295,34 +295,30 @@ TEST(StateTransaction, setColorXY) |
| 295 | 295 | const float y = 0.8f; |
| 296 | 296 | nlohmann::json request = {{"xy", {x, y}}}; |
| 297 | 297 | nlohmann::json response = {{{"success", {{"/path/xy", {x, y}}}}}}; |
| 298 | + nlohmann::json state = {{"on", true}, | |
| 299 | + {"xy", | |
| 300 | + { | |
| 301 | + x, | |
| 302 | + y, | |
| 303 | + }}, | |
| 304 | + {"colormode", "hs"}}; | |
| 298 | 305 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 299 | - EXPECT_TRUE(StateTransaction(commands, "/path", | |
| 300 | - {{"on", true}, | |
| 301 | - {"xy", | |
| 302 | - { | |
| 303 | - x, | |
| 304 | - y, | |
| 305 | - }}, | |
| 306 | - {"colormode", "hs"}}) | |
| 307 | - .setColorXY(x, y) | |
| 308 | - .commit()); | |
| 306 | + EXPECT_TRUE(StateTransaction(commands, "/path", &state).setColorXY(x, y).commit()); | |
| 309 | 307 | Mock::VerifyAndClearExpectations(handler.get()); |
| 310 | 308 | } |
| 311 | 309 | // No request |
| 312 | 310 | { |
| 313 | 311 | const float x = 0.5f; |
| 314 | 312 | const float y = 0.8f; |
| 313 | + nlohmann::json state = {{"on", true}, | |
| 314 | + {"xy", | |
| 315 | + { | |
| 316 | + x, | |
| 317 | + y, | |
| 318 | + }}, | |
| 319 | + {"colormode", "xy"}}; | |
| 315 | 320 | EXPECT_CALL(*handler, PUTJson(_, _, getBridgeIp(), getBridgePort())).Times(0); |
| 316 | - EXPECT_TRUE(StateTransaction(commands, "/path", | |
| 317 | - {{"on", true}, | |
| 318 | - {"xy", | |
| 319 | - { | |
| 320 | - x, | |
| 321 | - y, | |
| 322 | - }}, | |
| 323 | - {"colormode", "xy"}}) | |
| 324 | - .setColorXY(x, y) | |
| 325 | - .commit()); | |
| 321 | + EXPECT_TRUE(StateTransaction(commands, "/path", &state).setColorXY(x, y).commit()); | |
| 326 | 322 | Mock::VerifyAndClearExpectations(handler.get()); |
| 327 | 323 | } |
| 328 | 324 | } |
| ... | ... | @@ -338,7 +334,7 @@ TEST(StateTransaction, setColorTemperature) |
| 338 | 334 | nlohmann::json request = {{"on", true}, {"ct", ct}}; |
| 339 | 335 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/ct", ct}}}}}; |
| 340 | 336 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 341 | - EXPECT_TRUE(StateTransaction(commands, "/path", nlohmann::json::object()).setColorTemperature(ct).commit()); | |
| 337 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).setColorTemperature(ct).commit()); | |
| 342 | 338 | Mock::VerifyAndClearExpectations(handler.get()); |
| 343 | 339 | } |
| 344 | 340 | // Clamp |
| ... | ... | @@ -346,8 +342,9 @@ TEST(StateTransaction, setColorTemperature) |
| 346 | 342 | const int ct = 500; |
| 347 | 343 | nlohmann::json request = {{"ct", ct}}; |
| 348 | 344 | nlohmann::json response = {{{"success", {{"/path/ct", ct}}}}}; |
| 345 | + nlohmann::json state = {{"on", true}}; | |
| 349 | 346 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 350 | - EXPECT_TRUE(StateTransaction(commands, "/path", {{"on", true}}).setColorTemperature(520).commit()); | |
| 347 | + EXPECT_TRUE(StateTransaction(commands, "/path", &state).setColorTemperature(520).commit()); | |
| 351 | 348 | Mock::VerifyAndClearExpectations(handler.get()); |
| 352 | 349 | } |
| 353 | 350 | // Already on |
| ... | ... | @@ -355,8 +352,9 @@ TEST(StateTransaction, setColorTemperature) |
| 355 | 352 | const int ct = 240; |
| 356 | 353 | nlohmann::json request = {{"ct", ct}}; |
| 357 | 354 | nlohmann::json response = {{{"success", {{"/path/ct", ct}}}}}; |
| 355 | + nlohmann::json state = {{"on", true}}; | |
| 358 | 356 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 359 | - EXPECT_TRUE(StateTransaction(commands, "/path", {{"on", true}}).setColorTemperature(ct).commit()); | |
| 357 | + EXPECT_TRUE(StateTransaction(commands, "/path", &state).setColorTemperature(ct).commit()); | |
| 360 | 358 | Mock::VerifyAndClearExpectations(handler.get()); |
| 361 | 359 | } |
| 362 | 360 | // Wrong colormode |
| ... | ... | @@ -364,19 +362,17 @@ TEST(StateTransaction, setColorTemperature) |
| 364 | 362 | const int ct = 240; |
| 365 | 363 | nlohmann::json request = {{"ct", ct}}; |
| 366 | 364 | nlohmann::json response = {{{"success", {{"/path/ct", ct}}}}}; |
| 365 | + nlohmann::json state = {{"on", true}, {"ct", ct}, {"colormode", "hs"}}; | |
| 367 | 366 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 368 | - EXPECT_TRUE(StateTransaction(commands, "/path", {{"on", true}, {"ct", ct}, {"colormode", "hs"}}) | |
| 369 | - .setColorTemperature(ct) | |
| 370 | - .commit()); | |
| 367 | + EXPECT_TRUE(StateTransaction(commands, "/path", &state).setColorTemperature(ct).commit()); | |
| 371 | 368 | Mock::VerifyAndClearExpectations(handler.get()); |
| 372 | 369 | } |
| 373 | 370 | // No request |
| 374 | 371 | { |
| 375 | 372 | const int ct = 240; |
| 373 | + nlohmann::json state = {{"on", true}, {"ct", ct}, {"colormode", "ct"}}; | |
| 376 | 374 | EXPECT_CALL(*handler, PUTJson(_, _, getBridgeIp(), getBridgePort())).Times(0); |
| 377 | - EXPECT_TRUE(StateTransaction(commands, "/path", {{"on", true}, {"ct", ct}, {"colormode", "ct"}}) | |
| 378 | - .setColorTemperature(ct) | |
| 379 | - .commit()); | |
| 375 | + EXPECT_TRUE(StateTransaction(commands, "/path", &state).setColorTemperature(ct).commit()); | |
| 380 | 376 | Mock::VerifyAndClearExpectations(handler.get()); |
| 381 | 377 | } |
| 382 | 378 | } |
| ... | ... | @@ -391,7 +387,7 @@ TEST(StateTransaction, setColorLoop) |
| 391 | 387 | nlohmann::json request = {{"on", true}, {"effect", "colorloop"}}; |
| 392 | 388 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/effect", "colorloop"}}}}}; |
| 393 | 389 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 394 | - EXPECT_TRUE(StateTransaction(commands, "/path", nlohmann::json::object()).setColorLoop(true).commit()); | |
| 390 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).setColorLoop(true).commit()); | |
| 395 | 391 | Mock::VerifyAndClearExpectations(handler.get()); |
| 396 | 392 | } |
| 397 | 393 | // Set off |
| ... | ... | @@ -399,14 +395,14 @@ TEST(StateTransaction, setColorLoop) |
| 399 | 395 | nlohmann::json request = {{"on", true}, {"effect", "none"}}; |
| 400 | 396 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/effect", "none"}}}}}; |
| 401 | 397 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 402 | - EXPECT_TRUE(StateTransaction(commands, "/path", nlohmann::json::object()).setColorLoop(false).commit()); | |
| 398 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).setColorLoop(false).commit()); | |
| 403 | 399 | Mock::VerifyAndClearExpectations(handler.get()); |
| 404 | 400 | } |
| 405 | 401 | // No request |
| 406 | 402 | { |
| 403 | + nlohmann::json state = {{"on", true}, {"effect", "colorloop"}}; | |
| 407 | 404 | EXPECT_CALL(*handler, PUTJson(_, _, getBridgeIp(), getBridgePort())).Times(0); |
| 408 | - EXPECT_TRUE( | |
| 409 | - StateTransaction(commands, "/path", {{"on", true}, {"effect", "colorloop"}}).setColorLoop(true).commit()); | |
| 405 | + EXPECT_TRUE(StateTransaction(commands, "/path", &state).setColorLoop(true).commit()); | |
| 410 | 406 | Mock::VerifyAndClearExpectations(handler.get()); |
| 411 | 407 | } |
| 412 | 408 | } |
| ... | ... | @@ -421,7 +417,7 @@ TEST(StateTransaction, incrementBrightness) |
| 421 | 417 | nlohmann::json request = {{"bri_inc", inc}}; |
| 422 | 418 | nlohmann::json response = {{{"success", {{"/path/bri_inc", inc}}}}}; |
| 423 | 419 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 424 | - EXPECT_TRUE(StateTransaction(commands, "/path", nlohmann::json::object()).incrementBrightness(inc).commit()); | |
| 420 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).incrementBrightness(inc).commit()); | |
| 425 | 421 | Mock::VerifyAndClearExpectations(handler.get()); |
| 426 | 422 | } |
| 427 | 423 | // Clamp |
| ... | ... | @@ -430,7 +426,7 @@ TEST(StateTransaction, incrementBrightness) |
| 430 | 426 | nlohmann::json request = {{"bri_inc", inc}}; |
| 431 | 427 | nlohmann::json response = {{{"success", {{"/path/bri_inc", inc}}}}}; |
| 432 | 428 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 433 | - EXPECT_TRUE(StateTransaction(commands, "/path", nlohmann::json::object()).incrementBrightness(-300).commit()); | |
| 429 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).incrementBrightness(-300).commit()); | |
| 434 | 430 | Mock::VerifyAndClearExpectations(handler.get()); |
| 435 | 431 | } |
| 436 | 432 | } |
| ... | ... | @@ -445,7 +441,7 @@ TEST(StateTransaction, incrementSaturation) |
| 445 | 441 | nlohmann::json request = {{"sat_inc", inc}}; |
| 446 | 442 | nlohmann::json response = {{{"success", {{"/path/sat_inc", inc}}}}}; |
| 447 | 443 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 448 | - EXPECT_TRUE(StateTransaction(commands, "/path", nlohmann::json::object()).incrementSaturation(inc).commit()); | |
| 444 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).incrementSaturation(inc).commit()); | |
| 449 | 445 | Mock::VerifyAndClearExpectations(handler.get()); |
| 450 | 446 | } |
| 451 | 447 | // Clamp |
| ... | ... | @@ -454,7 +450,7 @@ TEST(StateTransaction, incrementSaturation) |
| 454 | 450 | nlohmann::json request = {{"sat_inc", inc}}; |
| 455 | 451 | nlohmann::json response = {{{"success", {{"/path/sat_inc", inc}}}}}; |
| 456 | 452 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 457 | - EXPECT_TRUE(StateTransaction(commands, "/path", nlohmann::json::object()).incrementSaturation(-300).commit()); | |
| 453 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).incrementSaturation(-300).commit()); | |
| 458 | 454 | Mock::VerifyAndClearExpectations(handler.get()); |
| 459 | 455 | } |
| 460 | 456 | } |
| ... | ... | @@ -469,7 +465,7 @@ TEST(StateTransaction, incrementHue) |
| 469 | 465 | nlohmann::json request = {{"hue_inc", inc}}; |
| 470 | 466 | nlohmann::json response = {{{"success", {{"/path/hue_inc", inc}}}}}; |
| 471 | 467 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 472 | - EXPECT_TRUE(StateTransaction(commands, "/path", nlohmann::json::object()).incrementHue(inc).commit()); | |
| 468 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).incrementHue(inc).commit()); | |
| 473 | 469 | Mock::VerifyAndClearExpectations(handler.get()); |
| 474 | 470 | } |
| 475 | 471 | // Clamp |
| ... | ... | @@ -478,7 +474,7 @@ TEST(StateTransaction, incrementHue) |
| 478 | 474 | nlohmann::json request = {{"hue_inc", inc}}; |
| 479 | 475 | nlohmann::json response = {{{"success", {{"/path/hue_inc", inc}}}}}; |
| 480 | 476 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 481 | - EXPECT_TRUE(StateTransaction(commands, "/path", nlohmann::json::object()).incrementHue(-300000).commit()); | |
| 477 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).incrementHue(-300000).commit()); | |
| 482 | 478 | Mock::VerifyAndClearExpectations(handler.get()); |
| 483 | 479 | } |
| 484 | 480 | } |
| ... | ... | @@ -493,8 +489,7 @@ TEST(StateTransaction, incrementColorTemperature) |
| 493 | 489 | nlohmann::json request = {{"ct_inc", inc}}; |
| 494 | 490 | nlohmann::json response = {{{"success", {{"/path/ct_inc", inc}}}}}; |
| 495 | 491 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 496 | - EXPECT_TRUE( | |
| 497 | - StateTransaction(commands, "/path", nlohmann::json::object()).incrementColorTemperature(inc).commit()); | |
| 492 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).incrementColorTemperature(inc).commit()); | |
| 498 | 493 | Mock::VerifyAndClearExpectations(handler.get()); |
| 499 | 494 | } |
| 500 | 495 | // Clamp |
| ... | ... | @@ -503,8 +498,7 @@ TEST(StateTransaction, incrementColorTemperature) |
| 503 | 498 | nlohmann::json request = {{"ct_inc", inc}}; |
| 504 | 499 | nlohmann::json response = {{{"success", {{"/path/ct_inc", inc}}}}}; |
| 505 | 500 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 506 | - EXPECT_TRUE( | |
| 507 | - StateTransaction(commands, "/path", nlohmann::json::object()).incrementColorTemperature(-300000).commit()); | |
| 501 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).incrementColorTemperature(-300000).commit()); | |
| 508 | 502 | Mock::VerifyAndClearExpectations(handler.get()); |
| 509 | 503 | } |
| 510 | 504 | } |
| ... | ... | @@ -520,8 +514,7 @@ TEST(StateTransaction, incrementColorXY) |
| 520 | 514 | nlohmann::json request = {{"xy_inc", {incX, incY}}}; |
| 521 | 515 | nlohmann::json response = {{{"success", {{"/path/xy_inc", {incX, incY}}}}}}; |
| 522 | 516 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 523 | - EXPECT_TRUE( | |
| 524 | - StateTransaction(commands, "/path", nlohmann::json::object()).incrementColorXY(incX, incY).commit()); | |
| 517 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).incrementColorXY(incX, incY).commit()); | |
| 525 | 518 | Mock::VerifyAndClearExpectations(handler.get()); |
| 526 | 519 | } |
| 527 | 520 | // Clamp |
| ... | ... | @@ -531,7 +524,7 @@ TEST(StateTransaction, incrementColorXY) |
| 531 | 524 | nlohmann::json request = {{"xy_inc", {incX, incY}}}; |
| 532 | 525 | nlohmann::json response = {{{"success", {{"/path/xy_inc", {incX, incY}}}}}}; |
| 533 | 526 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 534 | - EXPECT_TRUE(StateTransaction(commands, "/path", nlohmann::json::object()).incrementColorXY(1.f, -1.f).commit()); | |
| 527 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).incrementColorXY(1.f, -1.f).commit()); | |
| 535 | 528 | Mock::VerifyAndClearExpectations(handler.get()); |
| 536 | 529 | } |
| 537 | 530 | } |
| ... | ... | @@ -545,8 +538,7 @@ TEST(StateTransaction, setTransition) |
| 545 | 538 | nlohmann::json request = {{"on", true}, {"transitiontime", 2}}; |
| 546 | 539 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/transitiontime", 2}}}}}; |
| 547 | 540 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 548 | - EXPECT_TRUE( | |
| 549 | - StateTransaction(commands, "/path", nlohmann::json::object()).setOn(true).setTransition(2).commit()); | |
| 541 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).setOn(true).setTransition(2).commit()); | |
| 550 | 542 | Mock::VerifyAndClearExpectations(handler.get()); |
| 551 | 543 | } |
| 552 | 544 | // No transition time 4 |
| ... | ... | @@ -554,14 +546,13 @@ TEST(StateTransaction, setTransition) |
| 554 | 546 | nlohmann::json request = {{"on", true}}; |
| 555 | 547 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}}; |
| 556 | 548 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 557 | - EXPECT_TRUE( | |
| 558 | - StateTransaction(commands, "/path", nlohmann::json::object()).setOn(true).setTransition(4).commit()); | |
| 549 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).setOn(true).setTransition(4).commit()); | |
| 559 | 550 | Mock::VerifyAndClearExpectations(handler.get()); |
| 560 | 551 | } |
| 561 | 552 | // No request with only transition |
| 562 | 553 | { |
| 563 | 554 | EXPECT_CALL(*handler, PUTJson(_, _, getBridgeIp(), getBridgePort())).Times(0); |
| 564 | - EXPECT_TRUE(StateTransaction(commands, "/path", nlohmann::json::object()).setTransition(2).commit()); | |
| 555 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).setTransition(2).commit()); | |
| 565 | 556 | Mock::VerifyAndClearExpectations(handler.get()); |
| 566 | 557 | } |
| 567 | 558 | } |
| ... | ... | @@ -575,15 +566,16 @@ TEST(StateTransaction, alert) |
| 575 | 566 | nlohmann::json request = {{"alert", "select"}}; |
| 576 | 567 | nlohmann::json response = {{{"success", {{"/path/alert", "select"}}}}}; |
| 577 | 568 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 578 | - EXPECT_TRUE(StateTransaction(commands, "/path", nlohmann::json::object()).alert().commit()); | |
| 569 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).alert().commit()); | |
| 579 | 570 | Mock::VerifyAndClearExpectations(handler.get()); |
| 580 | 571 | } |
| 581 | 572 | // Also alert when in state |
| 582 | 573 | { |
| 583 | 574 | nlohmann::json request = {{"alert", "select"}}; |
| 584 | 575 | nlohmann::json response = {{{"success", {{"/path/alert", "select"}}}}}; |
| 576 | + nlohmann::json state = {{"alert", "select"}}; | |
| 585 | 577 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 586 | - EXPECT_TRUE(StateTransaction(commands, "/path", {{"alert", "select"}}).alert().commit()); | |
| 578 | + EXPECT_TRUE(StateTransaction(commands, "/path", &state).alert().commit()); | |
| 587 | 579 | Mock::VerifyAndClearExpectations(handler.get()); |
| 588 | 580 | } |
| 589 | 581 | } |
| ... | ... | @@ -597,15 +589,16 @@ TEST(StateTransaction, longAlert) |
| 597 | 589 | nlohmann::json request = {{"alert", "lselect"}}; |
| 598 | 590 | nlohmann::json response = {{{"success", {{"/path/alert", "lselect"}}}}}; |
| 599 | 591 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 600 | - EXPECT_TRUE(StateTransaction(commands, "/path", nlohmann::json::object()).longAlert().commit()); | |
| 592 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).longAlert().commit()); | |
| 601 | 593 | Mock::VerifyAndClearExpectations(handler.get()); |
| 602 | 594 | } |
| 603 | 595 | // Also alert when in state |
| 604 | 596 | { |
| 605 | 597 | nlohmann::json request = {{"alert", "lselect"}}; |
| 606 | 598 | nlohmann::json response = {{{"success", {{"/path/alert", "lselect"}}}}}; |
| 599 | + nlohmann::json state = {{"alert", "lselect"}}; | |
| 607 | 600 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 608 | - EXPECT_TRUE(StateTransaction(commands, "/path", {{"alert", "lselect"}}).longAlert().commit()); | |
| 601 | + EXPECT_TRUE(StateTransaction(commands, "/path", &state).longAlert().commit()); | |
| 609 | 602 | Mock::VerifyAndClearExpectations(handler.get()); |
| 610 | 603 | } |
| 611 | 604 | } |
| ... | ... | @@ -619,15 +612,16 @@ TEST(StateTransaction, stopAlert) |
| 619 | 612 | nlohmann::json request = {{"alert", "none"}}; |
| 620 | 613 | nlohmann::json response = {{{"success", {{"/path/alert", "none"}}}}}; |
| 621 | 614 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 622 | - EXPECT_TRUE(StateTransaction(commands, "/path", nlohmann::json::object()).stopAlert().commit()); | |
| 615 | + EXPECT_TRUE(StateTransaction(commands, "/path", nullptr).stopAlert().commit()); | |
| 623 | 616 | Mock::VerifyAndClearExpectations(handler.get()); |
| 624 | 617 | } |
| 625 | 618 | // Also alert when in state |
| 626 | 619 | { |
| 627 | 620 | nlohmann::json request = {{"alert", "none"}}; |
| 628 | 621 | nlohmann::json response = {{{"success", {{"/path/alert", "none"}}}}}; |
| 622 | + nlohmann::json state = {{"alert", "none"}}; | |
| 629 | 623 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); |
| 630 | - EXPECT_TRUE(StateTransaction(commands, "/path", {{"alert", "none"}}).stopAlert().commit()); | |
| 624 | + EXPECT_TRUE(StateTransaction(commands, "/path", &state).stopAlert().commit()); | |
| 631 | 625 | Mock::VerifyAndClearExpectations(handler.get()); |
| 632 | 626 | } |
| 633 | 627 | } | ... | ... |