diff --git a/hueplusplus/ExtendedColorHueStrategy.cpp b/hueplusplus/ExtendedColorHueStrategy.cpp index debbfcd..6199855 100755 --- a/hueplusplus/ExtendedColorHueStrategy.cpp +++ b/hueplusplus/ExtendedColorHueStrategy.cpp @@ -31,12 +31,12 @@ bool ExtendedColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const { light.refreshState(); - std::string cType = light.state["state"]["colormode"]; - bool on = light.state["state"]["on"]; + std::string cType = light.state["state"]["colormode"].get(); + bool on = light.state["state"]["on"].get(); if (cType == "hs") { - uint16_t oldHue = light.state["state"]["hue"]; - uint8_t oldSat = light.state["state"]["sat"]; + uint16_t oldHue = light.state["state"]["hue"].get(); + uint8_t oldSat = light.state["state"]["sat"].get(); if (!light.setColorHueSaturation(hue, sat, 1)) { return false; @@ -59,8 +59,8 @@ bool ExtendedColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, Hue } else if (cType == "xy") { - float oldX = light.state["state"]["xy"][0]; - float oldY = light.state["state"]["xy"][1]; + float oldX = light.state["state"]["xy"][0].get(); + float oldY = light.state["state"]["xy"][1].get(); if (!light.setColorHueSaturation(hue, sat, 1)) { return false; @@ -83,7 +83,7 @@ bool ExtendedColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, Hue } else if (cType == "ct") { - uint16_t oldCT = light.state["state"]["ct"]; + uint16_t oldCT = light.state["state"]["ct"].get(); if (!light.setColorHueSaturation(hue, sat, 1)) { return false; @@ -113,12 +113,12 @@ bool ExtendedColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, Hue bool ExtendedColorHueStrategy::alertXY(float x, float y, HueLight& light) const { light.refreshState(); - std::string cType = light.state["state"]["colormode"]; - bool on = light.state["state"]["on"]; + std::string cType = light.state["state"]["colormode"].get(); + bool on = light.state["state"]["on"].get(); if (cType == "hs") { - uint16_t oldHue = light.state["state"]["hue"]; - uint8_t oldSat = light.state["state"]["sat"]; + uint16_t oldHue = light.state["state"]["hue"].get(); + uint8_t oldSat = light.state["state"]["sat"].get(); if (!light.setColorXY(x, y, 1)) { return false; @@ -141,8 +141,8 @@ bool ExtendedColorHueStrategy::alertXY(float x, float y, HueLight& light) const } else if (cType == "xy") { - float oldX = light.state["state"]["xy"][0]; - float oldY = light.state["state"]["xy"][1]; + float oldX = light.state["state"]["xy"][0].get(); + float oldY = light.state["state"]["xy"][1].get(); if (!light.setColorXY(x, y, 1)) { return false; @@ -165,7 +165,7 @@ bool ExtendedColorHueStrategy::alertXY(float x, float y, HueLight& light) const } else if (cType == "ct") { - uint16_t oldCT = light.state["state"]["ct"]; + uint16_t oldCT = light.state["state"]["ct"].get(); if (!light.setColorXY(x, y, 1)) { return false; @@ -195,12 +195,12 @@ bool ExtendedColorHueStrategy::alertXY(float x, float y, HueLight& light) const bool ExtendedColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const { light.refreshState(); - std::string cType = light.state["state"]["colormode"]; - bool on = light.state["state"]["on"]; + std::string cType = light.state["state"]["colormode"].get(); + bool on = light.state["state"]["on"].get(); if (cType == "hs") { - uint16_t oldHue = light.state["state"]["hue"]; - uint8_t oldSat = light.state["state"]["sat"]; + uint16_t oldHue = light.state["state"]["hue"].get(); + uint8_t oldSat = light.state["state"]["sat"].get(); if (!light.setColorRGB(r, g, b, 1)) { return false; @@ -223,8 +223,8 @@ bool ExtendedColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLigh } else if (cType == "xy") { - float oldX = light.state["state"]["xy"][0]; - float oldY = light.state["state"]["xy"][1]; + float oldX = light.state["state"]["xy"][0].get(); + float oldY = light.state["state"]["xy"][1].get(); if (!light.setColorRGB(r, g, b, 1)) { return false; @@ -247,7 +247,7 @@ bool ExtendedColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLigh } else if (cType == "ct") { - uint16_t oldCT = light.state["state"]["ct"]; + uint16_t oldCT = light.state["state"]["ct"].get(); if (!light.setColorRGB(r, g, b, 1)) { return false; diff --git a/hueplusplus/ExtendedColorTemperatureStrategy.cpp b/hueplusplus/ExtendedColorTemperatureStrategy.cpp index f1d2f94..202096a 100644 --- a/hueplusplus/ExtendedColorTemperatureStrategy.cpp +++ b/hueplusplus/ExtendedColorTemperatureStrategy.cpp @@ -71,12 +71,12 @@ bool ExtendedColorTemperatureStrategy::setColorTemperature( bool ExtendedColorTemperatureStrategy::alertTemperature(unsigned int mired, HueLight& light) const { light.refreshState(); - std::string cType = light.state["state"]["colormode"]; - bool on = light.state["state"]["on"]; + std::string cType = light.state["state"]["colormode"].get(); + bool on = light.state["state"]["on"].get(); if (cType == "hs") { - uint16_t oldHue = light.state["state"]["hue"]; - uint8_t oldSat = light.state["state"]["sat"]; + uint16_t oldHue = light.state["state"]["hue"].get(); + uint8_t oldSat = light.state["state"]["sat"].get(); if (!light.setColorTemperature(mired, 1)) { return false; @@ -99,8 +99,8 @@ bool ExtendedColorTemperatureStrategy::alertTemperature(unsigned int mired, HueL } else if (cType == "xy") { - float oldX = light.state["state"]["xy"][0]; - float oldY = light.state["state"]["xy"][1]; + float oldX = light.state["state"]["xy"][0].get(); + float oldY = light.state["state"]["xy"][1].get(); if (!light.setColorTemperature(mired, 1)) { return false; @@ -123,7 +123,7 @@ bool ExtendedColorTemperatureStrategy::alertTemperature(unsigned int mired, HueL } else if (cType == "ct") { - uint16_t oldCT = light.state["state"]["ct"]; + uint16_t oldCT = light.state["state"]["ct"].get(); if (!light.setColorTemperature(mired, 1)) { return false; diff --git a/hueplusplus/Hue.cpp b/hueplusplus/Hue.cpp index 6895644..fdaabad 100644 --- a/hueplusplus/Hue.cpp +++ b/hueplusplus/Hue.cpp @@ -183,7 +183,7 @@ std::string Hue::requestUsername() if (jsonUser != nullptr) { // [{"success":{"username": ""}}] - username = jsonUser; + username = jsonUser.get(); // Update commands with new username and ip commands = HueCommandAPI(ip, port, username, http_handler); std::cout << "Success! Link button was pressed!\n"; @@ -235,7 +235,7 @@ HueLight& Hue::getLight(int id) throw HueException(CURRENT_FILE_INFO, "Light id is not valid"); } // std::cout << state["lights"][std::to_string(id)] << std::endl; - std::string type = state["lights"][std::to_string(id)]["modelid"]; + std::string type = state["lights"][std::to_string(id)]["modelid"].get(); // std::cout << type << std::endl; if (type == "LCT001" || type == "LCT002" || type == "LCT003" || type == "LCT007" || type == "LLM001") { diff --git a/hueplusplus/HueLight.cpp b/hueplusplus/HueLight.cpp index 0091ef1..dc705ff 100644 --- a/hueplusplus/HueLight.cpp +++ b/hueplusplus/HueLight.cpp @@ -45,12 +45,12 @@ bool HueLight::Off(uint8_t transition) bool HueLight::isOn() { refreshState(); - return state["state"]["on"]; + return state["state"]["on"].get(); } bool HueLight::isOn() const { - return state["state"]["on"]; + return state["state"]["on"].get(); } int HueLight::getId() const @@ -60,30 +60,30 @@ int HueLight::getId() const std::string HueLight::getType() const { - return state["type"]; + return state["type"].get(); } std::string HueLight::getName() { refreshState(); - return state["name"]; + return state["name"].get(); } std::string HueLight::getName() const { - return state["name"]; + return state["name"].get(); } std::string HueLight::getModelId() const { - return state["modelid"]; + return state["modelid"].get(); } std::string HueLight::getUId() const { if (state.count("uniqueid")) { - return state["uniqueid"]; + return state["uniqueid"].get(); } return std::string(); } @@ -92,7 +92,7 @@ std::string HueLight::getManufacturername() const { if (state.count("manufacturername")) { - return state["manufacturername"]; + return state["manufacturername"].get(); } return std::string(); } @@ -101,7 +101,7 @@ std::string HueLight::getProductname() const { if (state.count("productname")) { - return state["productname"]; + return state["productname"].get(); } return std::string(); } @@ -110,7 +110,7 @@ std::string HueLight::getLuminaireUId() const { if (state.count("luminaireuniqueid")) { - return state["luminaireuniqueid"]; + return state["luminaireuniqueid"].get(); } return std::string(); } @@ -118,12 +118,12 @@ std::string HueLight::getLuminaireUId() const std::string HueLight::getSwVersion() { refreshState(); - return state["swversion"]; + return state["swversion"].get(); } std::string HueLight::getSwVersion() const { - return state["swversion"]; + return state["swversion"].get(); } bool HueLight::setName(const std::string& name) diff --git a/hueplusplus/SimpleBrightnessStrategy.cpp b/hueplusplus/SimpleBrightnessStrategy.cpp index d2d2352..d0d00ac 100644 --- a/hueplusplus/SimpleBrightnessStrategy.cpp +++ b/hueplusplus/SimpleBrightnessStrategy.cpp @@ -79,10 +79,10 @@ bool SimpleBrightnessStrategy::setBrightness(unsigned int bri, uint8_t transitio unsigned int SimpleBrightnessStrategy::getBrightness(HueLight& light) const { light.refreshState(); - return light.state["state"]["bri"]; + return light.state["state"]["bri"].get(); } unsigned int SimpleBrightnessStrategy::getBrightness(const HueLight& light) const { - return light.state["state"]["bri"]; + return light.state["state"]["bri"].get(); } diff --git a/hueplusplus/SimpleColorHueStrategy.cpp b/hueplusplus/SimpleColorHueStrategy.cpp index 3ab86a9..86c5ee4 100644 --- a/hueplusplus/SimpleColorHueStrategy.cpp +++ b/hueplusplus/SimpleColorHueStrategy.cpp @@ -221,12 +221,12 @@ bool SimpleColorHueStrategy::setColorLoop(bool on, HueLight& light) const bool SimpleColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const { light.refreshState(); - std::string cType = light.state["state"]["colormode"]; - bool on = light.state["state"]["on"]; + std::string cType = light.state["state"]["colormode"].get(); + bool on = light.state["state"]["on"].get(); if (cType == "hs") { - uint16_t oldHue = light.state["state"]["hue"]; - uint8_t oldSat = light.state["state"]["sat"]; + uint16_t oldHue = light.state["state"]["hue"].get(); + uint8_t oldSat = light.state["state"]["sat"].get(); if (!light.setColorHueSaturation(hue, sat, 1)) { return false; @@ -249,8 +249,8 @@ bool SimpleColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, HueLi } else if (cType == "xy") { - float oldX = light.state["state"]["xy"][0]; - float oldY = light.state["state"]["xy"][1]; + float oldX = light.state["state"]["xy"][0].get(); + float oldY = light.state["state"]["xy"][1].get(); if (!light.setColorHueSaturation(hue, sat, 1)) { return false; @@ -280,12 +280,12 @@ bool SimpleColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, HueLi bool SimpleColorHueStrategy::alertXY(float x, float y, HueLight& light) const { light.refreshState(); - std::string cType = light.state["state"]["colormode"]; - bool on = light.state["state"]["on"]; + std::string cType = light.state["state"]["colormode"].get(); + bool on = light.state["state"]["on"].get(); if (cType == "hs") { - uint16_t oldHue = light.state["state"]["hue"]; - uint8_t oldSat = light.state["state"]["sat"]; + uint16_t oldHue = light.state["state"]["hue"].get(); + uint8_t oldSat = light.state["state"]["sat"].get(); if (!light.setColorXY(x, y, 1)) { return false; @@ -308,8 +308,8 @@ bool SimpleColorHueStrategy::alertXY(float x, float y, HueLight& light) const } else if (cType == "xy") { - float oldX = light.state["state"]["xy"][0]; - float oldY = light.state["state"]["xy"][1]; + float oldX = light.state["state"]["xy"][0].get(); + float oldY = light.state["state"]["xy"][1].get(); if (!light.setColorXY(x, y, 1)) { return false; @@ -339,12 +339,12 @@ bool SimpleColorHueStrategy::alertXY(float x, float y, HueLight& light) const bool SimpleColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const { light.refreshState(); - std::string cType = light.state["state"]["colormode"]; - bool on = light.state["state"]["on"]; + std::string cType = light.state["state"]["colormode"].get(); + bool on = light.state["state"]["on"].get(); if (cType == "hs") { - uint16_t oldHue = light.state["state"]["hue"]; - uint8_t oldSat = light.state["state"]["sat"]; + uint16_t oldHue = light.state["state"]["hue"].get(); + uint8_t oldSat = light.state["state"]["sat"].get(); if (!light.setColorRGB(r, g, b, 1)) { return false; @@ -367,8 +367,8 @@ bool SimpleColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& } else if (cType == "xy") { - float oldX = light.state["state"]["xy"][0]; - float oldY = light.state["state"]["xy"][1]; + float oldX = light.state["state"]["xy"][0].get(); + float oldY = light.state["state"]["xy"][1].get(); if (!light.setColorRGB(r, g, b, 1)) { return false; @@ -398,25 +398,23 @@ bool SimpleColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& std::pair SimpleColorHueStrategy::getColorHueSaturation(HueLight& light) const { light.refreshState(); - return std::pair( - static_cast(light.state["state"]["hue"]), static_cast(light.state["state"]["sat"])); + return std::make_pair(light.state["state"]["hue"].get(), light.state["state"]["sat"].get()); } std::pair SimpleColorHueStrategy::getColorHueSaturation(const HueLight& light) const { - return std::pair( - static_cast(light.state["state"]["hue"]), static_cast(light.state["state"]["sat"])); + return std::make_pair(light.state["state"]["hue"].get(), light.state["state"]["sat"].get()); } std::pair SimpleColorHueStrategy::getColorXY(HueLight& light) const { light.refreshState(); - return std::pair(light.state["state"]["xy"][0], light.state["state"]["xy"][1]); + return std::make_pair(light.state["state"]["xy"][0].get(), light.state["state"]["xy"][1].get()); } std::pair SimpleColorHueStrategy::getColorXY(const HueLight& light) const { - return std::pair(light.state["state"]["xy"][0], light.state["state"]["xy"][1]); + return std::make_pair(light.state["state"]["xy"][0].get(), light.state["state"]["xy"][1].get()); } /*bool SimpleColorHueStrategy::pointInTriangle(float pointx, float pointy, float x0, float y0, float x1, float y1, float x2, float y2) diff --git a/hueplusplus/SimpleColorTemperatureStrategy.cpp b/hueplusplus/SimpleColorTemperatureStrategy.cpp index 7890a2b..8dac10f 100644 --- a/hueplusplus/SimpleColorTemperatureStrategy.cpp +++ b/hueplusplus/SimpleColorTemperatureStrategy.cpp @@ -70,11 +70,11 @@ bool SimpleColorTemperatureStrategy::setColorTemperature(unsigned int mired, uin bool SimpleColorTemperatureStrategy::alertTemperature(unsigned int mired, HueLight& light) const { light.refreshState(); - std::string cType = light.state["state"]["colormode"]; - bool on = light.state["state"]["on"]; + std::string cType = light.state["state"]["colormode"].get(); + bool on = light.state["state"]["on"].get(); if (cType == "ct") { - uint16_t oldCT = light.state["state"]["ct"]; + uint16_t oldCT = light.state["state"]["ct"].get(); if (!light.setColorTemperature(mired, 1)) { return false; @@ -104,10 +104,10 @@ bool SimpleColorTemperatureStrategy::alertTemperature(unsigned int mired, HueLig unsigned int SimpleColorTemperatureStrategy::getColorTemperature(HueLight& light) const { light.refreshState(); - return light.state["state"]["ct"]; + return light.state["state"]["ct"].get(); } unsigned int SimpleColorTemperatureStrategy::getColorTemperature(const HueLight& light) const { - return light.state["state"]["ct"]; + return light.state["state"]["ct"].get(); } diff --git a/hueplusplus/test/test_HueLight.cpp b/hueplusplus/test/test_HueLight.cpp index 5c74d6f..891f69e 100644 --- a/hueplusplus/test/test_HueLight.cpp +++ b/hueplusplus/test/test_HueLight.cpp @@ -385,9 +385,9 @@ TEST_F(HueLightTest, setName) HueLight test_light_2 = test_bridge.getLight(2); HueLight test_light_3 = test_bridge.getLight(3); - EXPECT_EQ(true, test_light_1.setName(expected_request["name"])); - EXPECT_EQ(false, test_light_2.setName(expected_request["name"])); - EXPECT_EQ(true, test_light_3.setName(expected_request["name"])); + EXPECT_EQ(true, test_light_1.setName(expected_request["name"].get())); + EXPECT_EQ(false, test_light_2.setName(expected_request["name"].get())); + EXPECT_EQ(true, test_light_3.setName(expected_request["name"].get())); } TEST_F(HueLightTest, getColorType)