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,15 +39,18 @@ namespace hueplusplus | ||
| 39 | //! \code | 39 | //! \code |
| 40 | //! light.transaction().setOn(true).setBrightness(29).setColorHue(3000).setColorSaturation(128).commit(); | 40 | //! light.transaction().setOn(true).setBrightness(29).setColorHue(3000).setColorSaturation(128).commit(); |
| 41 | //! \endcode | 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 | class StateTransaction | 45 | class StateTransaction |
| 43 | { | 46 | { |
| 44 | public: | 47 | public: |
| 45 | //! \brief Creates a StateTransaction to a group or light state | 48 | //! \brief Creates a StateTransaction to a group or light state |
| 46 | //! \param commands HueCommandAPI for making requests | 49 | //! \param commands HueCommandAPI for making requests |
| 47 | //! \param path Path to which the final PUT request is made (without username) | 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 | //! \brief Deleted copy constructor, do not store StateTransaction in a variable. | 55 | //! \brief Deleted copy constructor, do not store StateTransaction in a variable. |
| 53 | StateTransaction(const StateTransaction&) = delete; | 56 | StateTransaction(const StateTransaction&) = delete; |
| @@ -165,7 +168,7 @@ private: | @@ -165,7 +168,7 @@ private: | ||
| 165 | private: | 168 | private: |
| 166 | const HueCommandAPI& commands; | 169 | const HueCommandAPI& commands; |
| 167 | std::string path; | 170 | std::string path; |
| 168 | - nlohmann::json state; | 171 | + nlohmann::json* state; |
| 169 | nlohmann::json request; | 172 | nlohmann::json request; |
| 170 | }; | 173 | }; |
| 171 | 174 |
src/Group.cpp
| @@ -142,7 +142,7 @@ StateTransaction Group::transaction() | @@ -142,7 +142,7 @@ StateTransaction Group::transaction() | ||
| 142 | { | 142 | { |
| 143 | // Do not pass state, because it is not the state of ALL lights in the group | 143 | // Do not pass state, because it is not the state of ALL lights in the group |
| 144 | return StateTransaction( | 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 | void Group::setOn(bool on, uint8_t transition) | 148 | void Group::setOn(bool on, uint8_t transition) |
src/HueLight.cpp
| @@ -171,7 +171,7 @@ bool HueLight::alert() | @@ -171,7 +171,7 @@ bool HueLight::alert() | ||
| 171 | StateTransaction HueLight::transaction() | 171 | StateTransaction HueLight::transaction() |
| 172 | { | 172 | { |
| 173 | return StateTransaction( | 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 | void HueLight::refresh() | 177 | void HueLight::refresh() |
src/StateTransaction.cpp
| @@ -30,12 +30,9 @@ | @@ -30,12 +30,9 @@ | ||
| 30 | 30 | ||
| 31 | namespace hueplusplus | 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 | : commands(commands), path(path), state(currentState), request(nlohmann::json::object()) | 34 | : commands(commands), path(path), state(currentState), request(nlohmann::json::object()) |
| 36 | -{ | ||
| 37 | - assert(currentState.is_object()); | ||
| 38 | -} | 35 | +{} |
| 39 | 36 | ||
| 40 | bool StateTransaction::commit(bool trimRequest) && | 37 | bool StateTransaction::commit(bool trimRequest) && |
| 41 | { | 38 | { |
| @@ -46,16 +43,17 @@ bool StateTransaction::commit(bool trimRequest) && | @@ -46,16 +43,17 @@ bool StateTransaction::commit(bool trimRequest) && | ||
| 46 | // Empty request or request with only transition makes no sense | 43 | // Empty request or request with only transition makes no sense |
| 47 | if (!request.empty() && !(request.size() == 1 && request.count("transitiontime"))) | 44 | if (!request.empty() && !(request.size() == 1 && request.count("transitiontime"))) |
| 48 | { | 45 | { |
| 46 | + const nlohmann::json& stateJson = (state != nullptr) ? *state : nlohmann::json::object(); | ||
| 49 | if (!request.count("on")) | 47 | if (!request.count("on")) |
| 50 | { | 48 | { |
| 51 | - if (!state.value("on", false) | 49 | + if (!stateJson.value("on", false) |
| 52 | && (request.value("bri", 0) != 0 || request.count("effect") || request.count("hue") | 50 | && (request.value("bri", 0) != 0 || request.count("effect") || request.count("hue") |
| 53 | || request.count("sat") || request.count("xy") || request.count("ct"))) | 51 | || request.count("sat") || request.count("xy") || request.count("ct"))) |
| 54 | { | 52 | { |
| 55 | // Turn on if it was turned off | 53 | // Turn on if it was turned off |
| 56 | request["on"] = true; | 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 | // Turn off if brightness is 0 | 58 | // Turn off if brightness is 0 |
| 61 | request["on"] = false; | 59 | request["on"] = false; |
| @@ -63,7 +61,23 @@ bool StateTransaction::commit(bool trimRequest) && | @@ -63,7 +61,23 @@ bool StateTransaction::commit(bool trimRequest) && | ||
| 63 | } | 61 | } |
| 64 | 62 | ||
| 65 | nlohmann::json reply = commands.PUTRequest(path, request, CURRENT_FILE_INFO); | 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 | return true; | 82 | return true; |
| 69 | } | 83 | } |
| @@ -108,9 +122,9 @@ StateTransaction&& StateTransaction::setColorXY(float x, float y) && | @@ -108,9 +122,9 @@ StateTransaction&& StateTransaction::setColorXY(float x, float y) && | ||
| 108 | return std::move(*this); | 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 | request["bri"] = static_cast<int>(std::round(xy.brightness * 255.f)); | 128 | request["bri"] = static_cast<int>(std::round(xy.brightness * 255.f)); |
| 115 | 129 | ||
| 116 | return std::move(*this); | 130 | return std::move(*this); |
| @@ -189,7 +203,7 @@ void StateTransaction::trimRequest() | @@ -189,7 +203,7 @@ void StateTransaction::trimRequest() | ||
| 189 | = {{"sat", "hs"}, {"hue", "hs"}, {"xy", "xy"}, {"ct", "ct"}}; | 203 | = {{"sat", "hs"}, {"hue", "hs"}, {"xy", "xy"}, {"ct", "ct"}}; |
| 190 | static const std::set<std::string> otherRemove = {"on", "bri", "effect"}; | 204 | static const std::set<std::string> otherRemove = {"on", "bri", "effect"}; |
| 191 | // Skip when there is no state provided (e.g. for groups) | 205 | // Skip when there is no state provided (e.g. for groups) |
| 192 | - if (state.empty()) | 206 | + if (!state) |
| 193 | { | 207 | { |
| 194 | return; | 208 | return; |
| 195 | } | 209 | } |
| @@ -199,8 +213,8 @@ void StateTransaction::trimRequest() | @@ -199,8 +213,8 @@ void StateTransaction::trimRequest() | ||
| 199 | if (colormodeIt != colormodes.end()) | 213 | if (colormodeIt != colormodes.end()) |
| 200 | { | 214 | { |
| 201 | // Only erase color commands if colormode and value matches | 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 | // Compare xy using float comparison | 219 | // Compare xy using float comparison |
| 206 | if ((!it->is_array() && *stateIt == *it) | 220 | if ((!it->is_array() && *stateIt == *it) |
| @@ -214,7 +228,7 @@ void StateTransaction::trimRequest() | @@ -214,7 +228,7 @@ void StateTransaction::trimRequest() | ||
| 214 | } | 228 | } |
| 215 | else if (otherRemove.count(it.key())) | 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 | it = request.erase(it); | 233 | it = request.erase(it); |
| 220 | continue; | 234 | continue; |
test/test_SimpleBrightnessStrategy.cpp
| @@ -55,6 +55,7 @@ TEST(SimpleBrightnessStrategy, setBrightness) | @@ -55,6 +55,7 @@ TEST(SimpleBrightnessStrategy, setBrightness) | ||
| 55 | EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(0, 4, test_light)); | 55 | EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(0, 4, test_light)); |
| 56 | // Only set brightness, already off | 56 | // Only set brightness, already off |
| 57 | test_light.getState()["state"]["on"] = false; | 57 | test_light.getState()["state"]["on"] = false; |
| 58 | + test_light.getState()["state"].erase("bri"); | ||
| 58 | prep_ret = {{{"success", {{"/lights/1/state/bri", 0}}}}}; | 59 | prep_ret = {{{"success", {{"/lights/1/state/bri", 0}}}}}; |
| 59 | EXPECT_CALL(*handler, PUTJson(statePath, _, getBridgeIp(), getBridgePort())).Times(1).WillOnce(Return(prep_ret)); | 60 | EXPECT_CALL(*handler, PUTJson(statePath, _, getBridgeIp(), getBridgePort())).Times(1).WillOnce(Return(prep_ret)); |
| 60 | EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(0, 4, test_light)); | 61 | EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(0, 4, test_light)); |
| @@ -71,6 +72,7 @@ TEST(SimpleBrightnessStrategy, setBrightness) | @@ -71,6 +72,7 @@ TEST(SimpleBrightnessStrategy, setBrightness) | ||
| 71 | prep_ret[1]["success"]["/lights/1/state/bri"] = 254; | 72 | prep_ret[1]["success"]["/lights/1/state/bri"] = 254; |
| 72 | EXPECT_CALL(*handler, PUTJson(statePath, _, getBridgeIp(), getBridgePort())).Times(1).WillOnce(Return(prep_ret)); | 73 | EXPECT_CALL(*handler, PUTJson(statePath, _, getBridgeIp(), getBridgePort())).Times(1).WillOnce(Return(prep_ret)); |
| 73 | test_light.getState()["state"]["on"] = false; | 74 | test_light.getState()["state"]["on"] = false; |
| 75 | + test_light.getState()["state"]["bri"] = 50; | ||
| 74 | EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(255, 6, test_light)); | 76 | EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(255, 6, test_light)); |
| 75 | } | 77 | } |
| 76 | 78 |
test/test_StateTransaction.cpp
| @@ -20,9 +20,10 @@ | @@ -20,9 +20,10 @@ | ||
| 20 | along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | 20 | along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. |
| 21 | **/ | 21 | **/ |
| 22 | 22 | ||
| 23 | -#include <gtest/gtest.h> | ||
| 24 | #include <hueplusplus/StateTransaction.h> | 23 | #include <hueplusplus/StateTransaction.h> |
| 25 | 24 | ||
| 25 | +#include <gtest/gtest.h> | ||
| 26 | + | ||
| 26 | #include "testhelper.h" | 27 | #include "testhelper.h" |
| 27 | 28 | ||
| 28 | #include "mocks/mock_HttpHandler.h" | 29 | #include "mocks/mock_HttpHandler.h" |
| @@ -37,7 +38,7 @@ TEST(StateTransaction, commit) | @@ -37,7 +38,7 @@ TEST(StateTransaction, commit) | ||
| 37 | const std::string requestPath = "/api/" + getBridgeUsername() + "/path"; | 38 | const std::string requestPath = "/api/" + getBridgeUsername() + "/path"; |
| 38 | { | 39 | { |
| 39 | EXPECT_CALL(*handler, PUTJson(_, _, getBridgeIp(), getBridgePort())).Times(0); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 42 | Mock::VerifyAndClearExpectations(handler.get()); |
| 42 | } | 43 | } |
| 43 | // Explicit off overrides brightness | 44 | // Explicit off overrides brightness |
| @@ -45,17 +46,16 @@ TEST(StateTransaction, commit) | @@ -45,17 +46,16 @@ TEST(StateTransaction, commit) | ||
| 45 | nlohmann::json request = {{"on", false}, {"bri", 100}}; | 46 | nlohmann::json request = {{"on", false}, {"bri", 100}}; |
| 46 | nlohmann::json response = {{{"success", {{"/path/on", false}}}}, {{"success", {{"/path/bri", 100}}}}}; | 47 | nlohmann::json response = {{{"success", {{"/path/on", false}}}}, {{"success", {{"/path/bri", 100}}}}}; |
| 47 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 50 | Mock::VerifyAndClearExpectations(handler.get()); |
| 51 | } | 51 | } |
| 52 | // Do not trim | 52 | // Do not trim |
| 53 | { | 53 | { |
| 54 | const nlohmann::json request = {{"on", false}, {"bri", 100}}; | 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 | nlohmann::json response = {{{"success", {{"/path/on", false}}}}, {{"success", {{"/path/bri", 100}}}}}; | 56 | nlohmann::json response = {{{"success", {{"/path/on", false}}}}, {{"success", {{"/path/bri", 100}}}}}; |
| 57 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 59 | Mock::VerifyAndClearExpectations(handler.get()); |
| 60 | } | 60 | } |
| 61 | } | 61 | } |
| @@ -67,10 +67,8 @@ TEST(StateTransaction, toScheduleCommand) | @@ -67,10 +67,8 @@ TEST(StateTransaction, toScheduleCommand) | ||
| 67 | const std::string requestPath = "/api/" + getBridgeUsername() + "/path"; | 67 | const std::string requestPath = "/api/" + getBridgeUsername() + "/path"; |
| 68 | nlohmann::json request = {{"on", false}, {"bri", 100}}; | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 72 | Mock::VerifyAndClearExpectations(handler.get()); |
| 75 | EXPECT_EQ(ScheduleCommand::Method::put, command.getMethod()); | 73 | EXPECT_EQ(ScheduleCommand::Method::put, command.getMethod()); |
| 76 | EXPECT_EQ(request, command.getBody()); | 74 | EXPECT_EQ(request, command.getBody()); |
| @@ -87,7 +85,7 @@ TEST(StateTransaction, setOn) | @@ -87,7 +85,7 @@ TEST(StateTransaction, setOn) | ||
| 87 | nlohmann::json request = {{"on", true}}; | 85 | nlohmann::json request = {{"on", true}}; |
| 88 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}}; | 86 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}}; |
| 89 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 89 | Mock::VerifyAndClearExpectations(handler.get()); |
| 92 | } | 90 | } |
| 93 | // Set off | 91 | // Set off |
| @@ -95,7 +93,7 @@ TEST(StateTransaction, setOn) | @@ -95,7 +93,7 @@ TEST(StateTransaction, setOn) | ||
| 95 | nlohmann::json request = {{"on", false}}; | 93 | nlohmann::json request = {{"on", false}}; |
| 96 | nlohmann::json response = {{{"success", {{"/path/on", false}}}}}; | 94 | nlohmann::json response = {{{"success", {{"/path/on", false}}}}}; |
| 97 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 97 | Mock::VerifyAndClearExpectations(handler.get()); |
| 100 | } | 98 | } |
| 101 | // Fail | 99 | // Fail |
| @@ -103,13 +101,14 @@ TEST(StateTransaction, setOn) | @@ -103,13 +101,14 @@ TEST(StateTransaction, setOn) | ||
| 103 | nlohmann::json request = {{"on", false}}; | 101 | nlohmann::json request = {{"on", false}}; |
| 104 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}}; | 102 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}}; |
| 105 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 105 | Mock::VerifyAndClearExpectations(handler.get()); |
| 108 | } | 106 | } |
| 109 | // No change requested | 107 | // No change requested |
| 110 | { | 108 | { |
| 109 | + nlohmann::json state = {{"on", false}}; | ||
| 111 | EXPECT_CALL(*handler, PUTJson(_, _, getBridgeIp(), getBridgePort())).Times(0); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 112 | Mock::VerifyAndClearExpectations(handler.get()); |
| 114 | } | 113 | } |
| 115 | } | 114 | } |
| @@ -125,7 +124,7 @@ TEST(StateTransaction, setBrightness) | @@ -125,7 +124,7 @@ TEST(StateTransaction, setBrightness) | ||
| 125 | nlohmann::json request = {{"on", true}, {"bri", bri}}; | 124 | nlohmann::json request = {{"on", true}, {"bri", bri}}; |
| 126 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/bri", bri}}}}}; | 125 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/bri", bri}}}}}; |
| 127 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 128 | Mock::VerifyAndClearExpectations(handler.get()); |
| 130 | } | 129 | } |
| 131 | // Clamp to 254 | 130 | // Clamp to 254 |
| @@ -134,7 +133,7 @@ TEST(StateTransaction, setBrightness) | @@ -134,7 +133,7 @@ TEST(StateTransaction, setBrightness) | ||
| 134 | nlohmann::json request = {{"on", true}, {"bri", bri}}; | 133 | nlohmann::json request = {{"on", true}, {"bri", bri}}; |
| 135 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/bri", bri}}}}}; | 134 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/bri", bri}}}}}; |
| 136 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 137 | Mock::VerifyAndClearExpectations(handler.get()); |
| 139 | } | 138 | } |
| 140 | // Already off | 139 | // Already off |
| @@ -142,15 +141,17 @@ TEST(StateTransaction, setBrightness) | @@ -142,15 +141,17 @@ TEST(StateTransaction, setBrightness) | ||
| 142 | const int bri = 0; | 141 | const int bri = 0; |
| 143 | nlohmann::json request = {{"bri", bri}}; | 142 | nlohmann::json request = {{"bri", bri}}; |
| 144 | nlohmann::json response = {{{"success", {{"/path/bri", bri}}}}}; | 143 | nlohmann::json response = {{{"success", {{"/path/bri", bri}}}}}; |
| 144 | + nlohmann::json state = {{"on", false}}; | ||
| 145 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 147 | Mock::VerifyAndClearExpectations(handler.get()); |
| 148 | } | 148 | } |
| 149 | // No change requested | 149 | // No change requested |
| 150 | { | 150 | { |
| 151 | const int bri = 120; | 151 | const int bri = 120; |
| 152 | + nlohmann::json state = {{"on", true}, {"bri", bri}}; | ||
| 152 | EXPECT_CALL(*handler, PUTJson(_, _, getBridgeIp(), getBridgePort())).Times(0); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 155 | Mock::VerifyAndClearExpectations(handler.get()); |
| 155 | } | 156 | } |
| 156 | } | 157 | } |
| @@ -166,7 +167,7 @@ TEST(StateTransaction, setColorHue) | @@ -166,7 +167,7 @@ TEST(StateTransaction, setColorHue) | ||
| 166 | nlohmann::json request = {{"on", true}, {"hue", hue}}; | 167 | nlohmann::json request = {{"on", true}, {"hue", hue}}; |
| 167 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/hue", hue}}}}}; | 168 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/hue", hue}}}}}; |
| 168 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 171 | Mock::VerifyAndClearExpectations(handler.get()); |
| 171 | } | 172 | } |
| 172 | // Already on | 173 | // Already on |
| @@ -174,8 +175,9 @@ TEST(StateTransaction, setColorHue) | @@ -174,8 +175,9 @@ TEST(StateTransaction, setColorHue) | ||
| 174 | const int hue = 2159; | 175 | const int hue = 2159; |
| 175 | nlohmann::json request = {{"hue", hue}}; | 176 | nlohmann::json request = {{"hue", hue}}; |
| 176 | nlohmann::json response = {{{"success", {{"/path/hue", hue}}}}}; | 177 | nlohmann::json response = {{{"success", {{"/path/hue", hue}}}}}; |
| 178 | + nlohmann::json state = {{"on", true}}; | ||
| 177 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 181 | Mock::VerifyAndClearExpectations(handler.get()); |
| 180 | } | 182 | } |
| 181 | // Wrong colormode | 183 | // Wrong colormode |
| @@ -183,19 +185,17 @@ TEST(StateTransaction, setColorHue) | @@ -183,19 +185,17 @@ TEST(StateTransaction, setColorHue) | ||
| 183 | const int hue = 2159; | 185 | const int hue = 2159; |
| 184 | nlohmann::json request = {{"hue", hue}}; | 186 | nlohmann::json request = {{"hue", hue}}; |
| 185 | nlohmann::json response = {{{"success", {{"/path/hue", hue}}}}}; | 187 | nlohmann::json response = {{{"success", {{"/path/hue", hue}}}}}; |
| 188 | + nlohmann::json state = {{"on", true}, {"hue", hue}, {"colormode", "ct"}}; | ||
| 186 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 191 | Mock::VerifyAndClearExpectations(handler.get()); |
| 191 | } | 192 | } |
| 192 | // No request | 193 | // No request |
| 193 | { | 194 | { |
| 194 | const int hue = 2159; | 195 | const int hue = 2159; |
| 196 | + nlohmann::json state = {{"on", true}, {"hue", hue}, {"colormode", "hs"}}; | ||
| 195 | EXPECT_CALL(*handler, PUTJson(_, _, getBridgeIp(), getBridgePort())).Times(0); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 199 | Mock::VerifyAndClearExpectations(handler.get()); |
| 200 | } | 200 | } |
| 201 | } | 201 | } |
| @@ -211,7 +211,7 @@ TEST(StateTransaction, setColorSaturation) | @@ -211,7 +211,7 @@ TEST(StateTransaction, setColorSaturation) | ||
| 211 | nlohmann::json request = {{"on", true}, {"sat", sat}}; | 211 | nlohmann::json request = {{"on", true}, {"sat", sat}}; |
| 212 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/sat", sat}}}}}; | 212 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/sat", sat}}}}}; |
| 213 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 215 | Mock::VerifyAndClearExpectations(handler.get()); |
| 216 | } | 216 | } |
| 217 | // Clamp to 254 | 217 | // Clamp to 254 |
| @@ -220,7 +220,7 @@ TEST(StateTransaction, setColorSaturation) | @@ -220,7 +220,7 @@ TEST(StateTransaction, setColorSaturation) | ||
| 220 | nlohmann::json request = {{"on", true}, {"sat", sat}}; | 220 | nlohmann::json request = {{"on", true}, {"sat", sat}}; |
| 221 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/sat", sat}}}}}; | 221 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/sat", sat}}}}}; |
| 222 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 224 | Mock::VerifyAndClearExpectations(handler.get()); |
| 225 | } | 225 | } |
| 226 | // Already on | 226 | // Already on |
| @@ -228,8 +228,9 @@ TEST(StateTransaction, setColorSaturation) | @@ -228,8 +228,9 @@ TEST(StateTransaction, setColorSaturation) | ||
| 228 | const int sat = 125; | 228 | const int sat = 125; |
| 229 | nlohmann::json request = {{"sat", sat}}; | 229 | nlohmann::json request = {{"sat", sat}}; |
| 230 | nlohmann::json response = {{{"success", {{"/path/sat", sat}}}}}; | 230 | nlohmann::json response = {{{"success", {{"/path/sat", sat}}}}}; |
| 231 | + nlohmann::json state = {{"on", true}}; | ||
| 231 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 234 | Mock::VerifyAndClearExpectations(handler.get()); |
| 234 | } | 235 | } |
| 235 | // Wrong colormode | 236 | // Wrong colormode |
| @@ -237,19 +238,17 @@ TEST(StateTransaction, setColorSaturation) | @@ -237,19 +238,17 @@ TEST(StateTransaction, setColorSaturation) | ||
| 237 | const int sat = 125; | 238 | const int sat = 125; |
| 238 | nlohmann::json request = {{"sat", sat}}; | 239 | nlohmann::json request = {{"sat", sat}}; |
| 239 | nlohmann::json response = {{{"success", {{"/path/sat", sat}}}}}; | 240 | nlohmann::json response = {{{"success", {{"/path/sat", sat}}}}}; |
| 241 | + nlohmann::json state = {{"on", true}, {"sat", sat}, {"colormode", "ct"}}; | ||
| 240 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 244 | Mock::VerifyAndClearExpectations(handler.get()); |
| 245 | } | 245 | } |
| 246 | // No request | 246 | // No request |
| 247 | { | 247 | { |
| 248 | const int sat = 125; | 248 | const int sat = 125; |
| 249 | + nlohmann::json state = {{"on", true}, {"sat", sat}, {"colormode", "hs"}}; | ||
| 249 | EXPECT_CALL(*handler, PUTJson(_, _, getBridgeIp(), getBridgePort())).Times(0); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 252 | Mock::VerifyAndClearExpectations(handler.get()); |
| 254 | } | 253 | } |
| 255 | } | 254 | } |
| @@ -266,7 +265,7 @@ TEST(StateTransaction, setColorXY) | @@ -266,7 +265,7 @@ TEST(StateTransaction, setColorXY) | ||
| 266 | nlohmann::json request = {{"on", true}, {"xy", {x, y}}}; | 265 | nlohmann::json request = {{"on", true}, {"xy", {x, y}}}; |
| 267 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/xy", {x, y}}}}}}; | 266 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/xy", {x, y}}}}}}; |
| 268 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 269 | Mock::VerifyAndClearExpectations(handler.get()); |
| 271 | } | 270 | } |
| 272 | // Clamp | 271 | // Clamp |
| @@ -276,7 +275,7 @@ TEST(StateTransaction, setColorXY) | @@ -276,7 +275,7 @@ TEST(StateTransaction, setColorXY) | ||
| 276 | nlohmann::json request = {{"on", true}, {"xy", {x, y}}}; | 275 | nlohmann::json request = {{"on", true}, {"xy", {x, y}}}; |
| 277 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/xy", {x, y}}}}}}; | 276 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/xy", {x, y}}}}}}; |
| 278 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 279 | Mock::VerifyAndClearExpectations(handler.get()); |
| 281 | } | 280 | } |
| 282 | // Already on | 281 | // Already on |
| @@ -285,8 +284,9 @@ TEST(StateTransaction, setColorXY) | @@ -285,8 +284,9 @@ TEST(StateTransaction, setColorXY) | ||
| 285 | const float y = 0.8f; | 284 | const float y = 0.8f; |
| 286 | nlohmann::json request = {{"xy", {x, y}}}; | 285 | nlohmann::json request = {{"xy", {x, y}}}; |
| 287 | nlohmann::json response = {{{"success", {{"/path/xy", {x, y}}}}}}; | 286 | nlohmann::json response = {{{"success", {{"/path/xy", {x, y}}}}}}; |
| 287 | + nlohmann::json state = {{"on", true}}; | ||
| 288 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 290 | Mock::VerifyAndClearExpectations(handler.get()); |
| 291 | } | 291 | } |
| 292 | // Wrong colormode | 292 | // Wrong colormode |
| @@ -295,34 +295,30 @@ TEST(StateTransaction, setColorXY) | @@ -295,34 +295,30 @@ TEST(StateTransaction, setColorXY) | ||
| 295 | const float y = 0.8f; | 295 | const float y = 0.8f; |
| 296 | nlohmann::json request = {{"xy", {x, y}}}; | 296 | nlohmann::json request = {{"xy", {x, y}}}; |
| 297 | nlohmann::json response = {{{"success", {{"/path/xy", {x, y}}}}}}; | 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 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 307 | Mock::VerifyAndClearExpectations(handler.get()); |
| 310 | } | 308 | } |
| 311 | // No request | 309 | // No request |
| 312 | { | 310 | { |
| 313 | const float x = 0.5f; | 311 | const float x = 0.5f; |
| 314 | const float y = 0.8f; | 312 | const float y = 0.8f; |
| 313 | + nlohmann::json state = {{"on", true}, | ||
| 314 | + {"xy", | ||
| 315 | + { | ||
| 316 | + x, | ||
| 317 | + y, | ||
| 318 | + }}, | ||
| 319 | + {"colormode", "xy"}}; | ||
| 315 | EXPECT_CALL(*handler, PUTJson(_, _, getBridgeIp(), getBridgePort())).Times(0); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 322 | Mock::VerifyAndClearExpectations(handler.get()); |
| 327 | } | 323 | } |
| 328 | } | 324 | } |
| @@ -338,7 +334,7 @@ TEST(StateTransaction, setColorTemperature) | @@ -338,7 +334,7 @@ TEST(StateTransaction, setColorTemperature) | ||
| 338 | nlohmann::json request = {{"on", true}, {"ct", ct}}; | 334 | nlohmann::json request = {{"on", true}, {"ct", ct}}; |
| 339 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/ct", ct}}}}}; | 335 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/ct", ct}}}}}; |
| 340 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 338 | Mock::VerifyAndClearExpectations(handler.get()); |
| 343 | } | 339 | } |
| 344 | // Clamp | 340 | // Clamp |
| @@ -346,8 +342,9 @@ TEST(StateTransaction, setColorTemperature) | @@ -346,8 +342,9 @@ TEST(StateTransaction, setColorTemperature) | ||
| 346 | const int ct = 500; | 342 | const int ct = 500; |
| 347 | nlohmann::json request = {{"ct", ct}}; | 343 | nlohmann::json request = {{"ct", ct}}; |
| 348 | nlohmann::json response = {{{"success", {{"/path/ct", ct}}}}}; | 344 | nlohmann::json response = {{{"success", {{"/path/ct", ct}}}}}; |
| 345 | + nlohmann::json state = {{"on", true}}; | ||
| 349 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 348 | Mock::VerifyAndClearExpectations(handler.get()); |
| 352 | } | 349 | } |
| 353 | // Already on | 350 | // Already on |
| @@ -355,8 +352,9 @@ TEST(StateTransaction, setColorTemperature) | @@ -355,8 +352,9 @@ TEST(StateTransaction, setColorTemperature) | ||
| 355 | const int ct = 240; | 352 | const int ct = 240; |
| 356 | nlohmann::json request = {{"ct", ct}}; | 353 | nlohmann::json request = {{"ct", ct}}; |
| 357 | nlohmann::json response = {{{"success", {{"/path/ct", ct}}}}}; | 354 | nlohmann::json response = {{{"success", {{"/path/ct", ct}}}}}; |
| 355 | + nlohmann::json state = {{"on", true}}; | ||
| 358 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 358 | Mock::VerifyAndClearExpectations(handler.get()); |
| 361 | } | 359 | } |
| 362 | // Wrong colormode | 360 | // Wrong colormode |
| @@ -364,19 +362,17 @@ TEST(StateTransaction, setColorTemperature) | @@ -364,19 +362,17 @@ TEST(StateTransaction, setColorTemperature) | ||
| 364 | const int ct = 240; | 362 | const int ct = 240; |
| 365 | nlohmann::json request = {{"ct", ct}}; | 363 | nlohmann::json request = {{"ct", ct}}; |
| 366 | nlohmann::json response = {{{"success", {{"/path/ct", ct}}}}}; | 364 | nlohmann::json response = {{{"success", {{"/path/ct", ct}}}}}; |
| 365 | + nlohmann::json state = {{"on", true}, {"ct", ct}, {"colormode", "hs"}}; | ||
| 367 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 368 | Mock::VerifyAndClearExpectations(handler.get()); |
| 372 | } | 369 | } |
| 373 | // No request | 370 | // No request |
| 374 | { | 371 | { |
| 375 | const int ct = 240; | 372 | const int ct = 240; |
| 373 | + nlohmann::json state = {{"on", true}, {"ct", ct}, {"colormode", "ct"}}; | ||
| 376 | EXPECT_CALL(*handler, PUTJson(_, _, getBridgeIp(), getBridgePort())).Times(0); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 376 | Mock::VerifyAndClearExpectations(handler.get()); |
| 381 | } | 377 | } |
| 382 | } | 378 | } |
| @@ -391,7 +387,7 @@ TEST(StateTransaction, setColorLoop) | @@ -391,7 +387,7 @@ TEST(StateTransaction, setColorLoop) | ||
| 391 | nlohmann::json request = {{"on", true}, {"effect", "colorloop"}}; | 387 | nlohmann::json request = {{"on", true}, {"effect", "colorloop"}}; |
| 392 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/effect", "colorloop"}}}}}; | 388 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/effect", "colorloop"}}}}}; |
| 393 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 391 | Mock::VerifyAndClearExpectations(handler.get()); |
| 396 | } | 392 | } |
| 397 | // Set off | 393 | // Set off |
| @@ -399,14 +395,14 @@ TEST(StateTransaction, setColorLoop) | @@ -399,14 +395,14 @@ TEST(StateTransaction, setColorLoop) | ||
| 399 | nlohmann::json request = {{"on", true}, {"effect", "none"}}; | 395 | nlohmann::json request = {{"on", true}, {"effect", "none"}}; |
| 400 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/effect", "none"}}}}}; | 396 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/effect", "none"}}}}}; |
| 401 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 399 | Mock::VerifyAndClearExpectations(handler.get()); |
| 404 | } | 400 | } |
| 405 | // No request | 401 | // No request |
| 406 | { | 402 | { |
| 403 | + nlohmann::json state = {{"on", true}, {"effect", "colorloop"}}; | ||
| 407 | EXPECT_CALL(*handler, PUTJson(_, _, getBridgeIp(), getBridgePort())).Times(0); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 406 | Mock::VerifyAndClearExpectations(handler.get()); |
| 411 | } | 407 | } |
| 412 | } | 408 | } |
| @@ -421,7 +417,7 @@ TEST(StateTransaction, incrementBrightness) | @@ -421,7 +417,7 @@ TEST(StateTransaction, incrementBrightness) | ||
| 421 | nlohmann::json request = {{"bri_inc", inc}}; | 417 | nlohmann::json request = {{"bri_inc", inc}}; |
| 422 | nlohmann::json response = {{{"success", {{"/path/bri_inc", inc}}}}}; | 418 | nlohmann::json response = {{{"success", {{"/path/bri_inc", inc}}}}}; |
| 423 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 421 | Mock::VerifyAndClearExpectations(handler.get()); |
| 426 | } | 422 | } |
| 427 | // Clamp | 423 | // Clamp |
| @@ -430,7 +426,7 @@ TEST(StateTransaction, incrementBrightness) | @@ -430,7 +426,7 @@ TEST(StateTransaction, incrementBrightness) | ||
| 430 | nlohmann::json request = {{"bri_inc", inc}}; | 426 | nlohmann::json request = {{"bri_inc", inc}}; |
| 431 | nlohmann::json response = {{{"success", {{"/path/bri_inc", inc}}}}}; | 427 | nlohmann::json response = {{{"success", {{"/path/bri_inc", inc}}}}}; |
| 432 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 430 | Mock::VerifyAndClearExpectations(handler.get()); |
| 435 | } | 431 | } |
| 436 | } | 432 | } |
| @@ -445,7 +441,7 @@ TEST(StateTransaction, incrementSaturation) | @@ -445,7 +441,7 @@ TEST(StateTransaction, incrementSaturation) | ||
| 445 | nlohmann::json request = {{"sat_inc", inc}}; | 441 | nlohmann::json request = {{"sat_inc", inc}}; |
| 446 | nlohmann::json response = {{{"success", {{"/path/sat_inc", inc}}}}}; | 442 | nlohmann::json response = {{{"success", {{"/path/sat_inc", inc}}}}}; |
| 447 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 445 | Mock::VerifyAndClearExpectations(handler.get()); |
| 450 | } | 446 | } |
| 451 | // Clamp | 447 | // Clamp |
| @@ -454,7 +450,7 @@ TEST(StateTransaction, incrementSaturation) | @@ -454,7 +450,7 @@ TEST(StateTransaction, incrementSaturation) | ||
| 454 | nlohmann::json request = {{"sat_inc", inc}}; | 450 | nlohmann::json request = {{"sat_inc", inc}}; |
| 455 | nlohmann::json response = {{{"success", {{"/path/sat_inc", inc}}}}}; | 451 | nlohmann::json response = {{{"success", {{"/path/sat_inc", inc}}}}}; |
| 456 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 454 | Mock::VerifyAndClearExpectations(handler.get()); |
| 459 | } | 455 | } |
| 460 | } | 456 | } |
| @@ -469,7 +465,7 @@ TEST(StateTransaction, incrementHue) | @@ -469,7 +465,7 @@ TEST(StateTransaction, incrementHue) | ||
| 469 | nlohmann::json request = {{"hue_inc", inc}}; | 465 | nlohmann::json request = {{"hue_inc", inc}}; |
| 470 | nlohmann::json response = {{{"success", {{"/path/hue_inc", inc}}}}}; | 466 | nlohmann::json response = {{{"success", {{"/path/hue_inc", inc}}}}}; |
| 471 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 469 | Mock::VerifyAndClearExpectations(handler.get()); |
| 474 | } | 470 | } |
| 475 | // Clamp | 471 | // Clamp |
| @@ -478,7 +474,7 @@ TEST(StateTransaction, incrementHue) | @@ -478,7 +474,7 @@ TEST(StateTransaction, incrementHue) | ||
| 478 | nlohmann::json request = {{"hue_inc", inc}}; | 474 | nlohmann::json request = {{"hue_inc", inc}}; |
| 479 | nlohmann::json response = {{{"success", {{"/path/hue_inc", inc}}}}}; | 475 | nlohmann::json response = {{{"success", {{"/path/hue_inc", inc}}}}}; |
| 480 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 478 | Mock::VerifyAndClearExpectations(handler.get()); |
| 483 | } | 479 | } |
| 484 | } | 480 | } |
| @@ -493,8 +489,7 @@ TEST(StateTransaction, incrementColorTemperature) | @@ -493,8 +489,7 @@ TEST(StateTransaction, incrementColorTemperature) | ||
| 493 | nlohmann::json request = {{"ct_inc", inc}}; | 489 | nlohmann::json request = {{"ct_inc", inc}}; |
| 494 | nlohmann::json response = {{{"success", {{"/path/ct_inc", inc}}}}}; | 490 | nlohmann::json response = {{{"success", {{"/path/ct_inc", inc}}}}}; |
| 495 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 493 | Mock::VerifyAndClearExpectations(handler.get()); |
| 499 | } | 494 | } |
| 500 | // Clamp | 495 | // Clamp |
| @@ -503,8 +498,7 @@ TEST(StateTransaction, incrementColorTemperature) | @@ -503,8 +498,7 @@ TEST(StateTransaction, incrementColorTemperature) | ||
| 503 | nlohmann::json request = {{"ct_inc", inc}}; | 498 | nlohmann::json request = {{"ct_inc", inc}}; |
| 504 | nlohmann::json response = {{{"success", {{"/path/ct_inc", inc}}}}}; | 499 | nlohmann::json response = {{{"success", {{"/path/ct_inc", inc}}}}}; |
| 505 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 502 | Mock::VerifyAndClearExpectations(handler.get()); |
| 509 | } | 503 | } |
| 510 | } | 504 | } |
| @@ -520,8 +514,7 @@ TEST(StateTransaction, incrementColorXY) | @@ -520,8 +514,7 @@ TEST(StateTransaction, incrementColorXY) | ||
| 520 | nlohmann::json request = {{"xy_inc", {incX, incY}}}; | 514 | nlohmann::json request = {{"xy_inc", {incX, incY}}}; |
| 521 | nlohmann::json response = {{{"success", {{"/path/xy_inc", {incX, incY}}}}}}; | 515 | nlohmann::json response = {{{"success", {{"/path/xy_inc", {incX, incY}}}}}}; |
| 522 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 518 | Mock::VerifyAndClearExpectations(handler.get()); |
| 526 | } | 519 | } |
| 527 | // Clamp | 520 | // Clamp |
| @@ -531,7 +524,7 @@ TEST(StateTransaction, incrementColorXY) | @@ -531,7 +524,7 @@ TEST(StateTransaction, incrementColorXY) | ||
| 531 | nlohmann::json request = {{"xy_inc", {incX, incY}}}; | 524 | nlohmann::json request = {{"xy_inc", {incX, incY}}}; |
| 532 | nlohmann::json response = {{{"success", {{"/path/xy_inc", {incX, incY}}}}}}; | 525 | nlohmann::json response = {{{"success", {{"/path/xy_inc", {incX, incY}}}}}}; |
| 533 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 528 | Mock::VerifyAndClearExpectations(handler.get()); |
| 536 | } | 529 | } |
| 537 | } | 530 | } |
| @@ -545,8 +538,7 @@ TEST(StateTransaction, setTransition) | @@ -545,8 +538,7 @@ TEST(StateTransaction, setTransition) | ||
| 545 | nlohmann::json request = {{"on", true}, {"transitiontime", 2}}; | 538 | nlohmann::json request = {{"on", true}, {"transitiontime", 2}}; |
| 546 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/transitiontime", 2}}}}}; | 539 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}, {{"success", {{"/path/transitiontime", 2}}}}}; |
| 547 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 542 | Mock::VerifyAndClearExpectations(handler.get()); |
| 551 | } | 543 | } |
| 552 | // No transition time 4 | 544 | // No transition time 4 |
| @@ -554,14 +546,13 @@ TEST(StateTransaction, setTransition) | @@ -554,14 +546,13 @@ TEST(StateTransaction, setTransition) | ||
| 554 | nlohmann::json request = {{"on", true}}; | 546 | nlohmann::json request = {{"on", true}}; |
| 555 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}}; | 547 | nlohmann::json response = {{{"success", {{"/path/on", true}}}}}; |
| 556 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 550 | Mock::VerifyAndClearExpectations(handler.get()); |
| 560 | } | 551 | } |
| 561 | // No request with only transition | 552 | // No request with only transition |
| 562 | { | 553 | { |
| 563 | EXPECT_CALL(*handler, PUTJson(_, _, getBridgeIp(), getBridgePort())).Times(0); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 556 | Mock::VerifyAndClearExpectations(handler.get()); |
| 566 | } | 557 | } |
| 567 | } | 558 | } |
| @@ -575,15 +566,16 @@ TEST(StateTransaction, alert) | @@ -575,15 +566,16 @@ TEST(StateTransaction, alert) | ||
| 575 | nlohmann::json request = {{"alert", "select"}}; | 566 | nlohmann::json request = {{"alert", "select"}}; |
| 576 | nlohmann::json response = {{{"success", {{"/path/alert", "select"}}}}}; | 567 | nlohmann::json response = {{{"success", {{"/path/alert", "select"}}}}}; |
| 577 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 570 | Mock::VerifyAndClearExpectations(handler.get()); |
| 580 | } | 571 | } |
| 581 | // Also alert when in state | 572 | // Also alert when in state |
| 582 | { | 573 | { |
| 583 | nlohmann::json request = {{"alert", "select"}}; | 574 | nlohmann::json request = {{"alert", "select"}}; |
| 584 | nlohmann::json response = {{{"success", {{"/path/alert", "select"}}}}}; | 575 | nlohmann::json response = {{{"success", {{"/path/alert", "select"}}}}}; |
| 576 | + nlohmann::json state = {{"alert", "select"}}; | ||
| 585 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 579 | Mock::VerifyAndClearExpectations(handler.get()); |
| 588 | } | 580 | } |
| 589 | } | 581 | } |
| @@ -597,15 +589,16 @@ TEST(StateTransaction, longAlert) | @@ -597,15 +589,16 @@ TEST(StateTransaction, longAlert) | ||
| 597 | nlohmann::json request = {{"alert", "lselect"}}; | 589 | nlohmann::json request = {{"alert", "lselect"}}; |
| 598 | nlohmann::json response = {{{"success", {{"/path/alert", "lselect"}}}}}; | 590 | nlohmann::json response = {{{"success", {{"/path/alert", "lselect"}}}}}; |
| 599 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 593 | Mock::VerifyAndClearExpectations(handler.get()); |
| 602 | } | 594 | } |
| 603 | // Also alert when in state | 595 | // Also alert when in state |
| 604 | { | 596 | { |
| 605 | nlohmann::json request = {{"alert", "lselect"}}; | 597 | nlohmann::json request = {{"alert", "lselect"}}; |
| 606 | nlohmann::json response = {{{"success", {{"/path/alert", "lselect"}}}}}; | 598 | nlohmann::json response = {{{"success", {{"/path/alert", "lselect"}}}}}; |
| 599 | + nlohmann::json state = {{"alert", "lselect"}}; | ||
| 607 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 602 | Mock::VerifyAndClearExpectations(handler.get()); |
| 610 | } | 603 | } |
| 611 | } | 604 | } |
| @@ -619,15 +612,16 @@ TEST(StateTransaction, stopAlert) | @@ -619,15 +612,16 @@ TEST(StateTransaction, stopAlert) | ||
| 619 | nlohmann::json request = {{"alert", "none"}}; | 612 | nlohmann::json request = {{"alert", "none"}}; |
| 620 | nlohmann::json response = {{{"success", {{"/path/alert", "none"}}}}}; | 613 | nlohmann::json response = {{{"success", {{"/path/alert", "none"}}}}}; |
| 621 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 616 | Mock::VerifyAndClearExpectations(handler.get()); |
| 624 | } | 617 | } |
| 625 | // Also alert when in state | 618 | // Also alert when in state |
| 626 | { | 619 | { |
| 627 | nlohmann::json request = {{"alert", "none"}}; | 620 | nlohmann::json request = {{"alert", "none"}}; |
| 628 | nlohmann::json response = {{{"success", {{"/path/alert", "none"}}}}}; | 621 | nlohmann::json response = {{{"success", {{"/path/alert", "none"}}}}}; |
| 622 | + nlohmann::json state = {{"alert", "none"}}; | ||
| 629 | EXPECT_CALL(*handler, PUTJson(requestPath, request, getBridgeIp(), getBridgePort())).WillOnce(Return(response)); | 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 | Mock::VerifyAndClearExpectations(handler.get()); | 625 | Mock::VerifyAndClearExpectations(handler.get()); |
| 632 | } | 626 | } |
| 633 | } | 627 | } |