Commit 83d4883211e61a66867f5736a96c667652ce333e
Committed by
Jan
1 parent
ceedfc1a
Remove all uses of implicit conversions from json.
These are prone to breaking in the future or with some compiler versions, so it is better to remove them.
Showing
8 changed files
with
74 additions
and
76 deletions
hueplusplus/ExtendedColorHueStrategy.cpp
| ... | ... | @@ -31,12 +31,12 @@ |
| 31 | 31 | bool ExtendedColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const |
| 32 | 32 | { |
| 33 | 33 | light.refreshState(); |
| 34 | - std::string cType = light.state["state"]["colormode"]; | |
| 35 | - bool on = light.state["state"]["on"]; | |
| 34 | + std::string cType = light.state["state"]["colormode"].get<std::string>(); | |
| 35 | + bool on = light.state["state"]["on"].get<bool>(); | |
| 36 | 36 | if (cType == "hs") |
| 37 | 37 | { |
| 38 | - uint16_t oldHue = light.state["state"]["hue"]; | |
| 39 | - uint8_t oldSat = light.state["state"]["sat"]; | |
| 38 | + uint16_t oldHue = light.state["state"]["hue"].get<uint16_t>(); | |
| 39 | + uint8_t oldSat = light.state["state"]["sat"].get<uint8_t>(); | |
| 40 | 40 | if (!light.setColorHueSaturation(hue, sat, 1)) |
| 41 | 41 | { |
| 42 | 42 | return false; |
| ... | ... | @@ -59,8 +59,8 @@ bool ExtendedColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, Hue |
| 59 | 59 | } |
| 60 | 60 | else if (cType == "xy") |
| 61 | 61 | { |
| 62 | - float oldX = light.state["state"]["xy"][0]; | |
| 63 | - float oldY = light.state["state"]["xy"][1]; | |
| 62 | + float oldX = light.state["state"]["xy"][0].get<float>(); | |
| 63 | + float oldY = light.state["state"]["xy"][1].get<float>(); | |
| 64 | 64 | if (!light.setColorHueSaturation(hue, sat, 1)) |
| 65 | 65 | { |
| 66 | 66 | return false; |
| ... | ... | @@ -83,7 +83,7 @@ bool ExtendedColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, Hue |
| 83 | 83 | } |
| 84 | 84 | else if (cType == "ct") |
| 85 | 85 | { |
| 86 | - uint16_t oldCT = light.state["state"]["ct"]; | |
| 86 | + uint16_t oldCT = light.state["state"]["ct"].get<uint16_t>(); | |
| 87 | 87 | if (!light.setColorHueSaturation(hue, sat, 1)) |
| 88 | 88 | { |
| 89 | 89 | return false; |
| ... | ... | @@ -113,12 +113,12 @@ bool ExtendedColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, Hue |
| 113 | 113 | bool ExtendedColorHueStrategy::alertXY(float x, float y, HueLight& light) const |
| 114 | 114 | { |
| 115 | 115 | light.refreshState(); |
| 116 | - std::string cType = light.state["state"]["colormode"]; | |
| 117 | - bool on = light.state["state"]["on"]; | |
| 116 | + std::string cType = light.state["state"]["colormode"].get<std::string>(); | |
| 117 | + bool on = light.state["state"]["on"].get<bool>(); | |
| 118 | 118 | if (cType == "hs") |
| 119 | 119 | { |
| 120 | - uint16_t oldHue = light.state["state"]["hue"]; | |
| 121 | - uint8_t oldSat = light.state["state"]["sat"]; | |
| 120 | + uint16_t oldHue = light.state["state"]["hue"].get<uint16_t>(); | |
| 121 | + uint8_t oldSat = light.state["state"]["sat"].get<uint8_t>(); | |
| 122 | 122 | if (!light.setColorXY(x, y, 1)) |
| 123 | 123 | { |
| 124 | 124 | return false; |
| ... | ... | @@ -141,8 +141,8 @@ bool ExtendedColorHueStrategy::alertXY(float x, float y, HueLight& light) const |
| 141 | 141 | } |
| 142 | 142 | else if (cType == "xy") |
| 143 | 143 | { |
| 144 | - float oldX = light.state["state"]["xy"][0]; | |
| 145 | - float oldY = light.state["state"]["xy"][1]; | |
| 144 | + float oldX = light.state["state"]["xy"][0].get<float>(); | |
| 145 | + float oldY = light.state["state"]["xy"][1].get<float>(); | |
| 146 | 146 | if (!light.setColorXY(x, y, 1)) |
| 147 | 147 | { |
| 148 | 148 | return false; |
| ... | ... | @@ -165,7 +165,7 @@ bool ExtendedColorHueStrategy::alertXY(float x, float y, HueLight& light) const |
| 165 | 165 | } |
| 166 | 166 | else if (cType == "ct") |
| 167 | 167 | { |
| 168 | - uint16_t oldCT = light.state["state"]["ct"]; | |
| 168 | + uint16_t oldCT = light.state["state"]["ct"].get<uint16_t>(); | |
| 169 | 169 | if (!light.setColorXY(x, y, 1)) |
| 170 | 170 | { |
| 171 | 171 | return false; |
| ... | ... | @@ -195,12 +195,12 @@ bool ExtendedColorHueStrategy::alertXY(float x, float y, HueLight& light) const |
| 195 | 195 | bool ExtendedColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const |
| 196 | 196 | { |
| 197 | 197 | light.refreshState(); |
| 198 | - std::string cType = light.state["state"]["colormode"]; | |
| 199 | - bool on = light.state["state"]["on"]; | |
| 198 | + std::string cType = light.state["state"]["colormode"].get<std::string>(); | |
| 199 | + bool on = light.state["state"]["on"].get<bool>(); | |
| 200 | 200 | if (cType == "hs") |
| 201 | 201 | { |
| 202 | - uint16_t oldHue = light.state["state"]["hue"]; | |
| 203 | - uint8_t oldSat = light.state["state"]["sat"]; | |
| 202 | + uint16_t oldHue = light.state["state"]["hue"].get<uint16_t>(); | |
| 203 | + uint8_t oldSat = light.state["state"]["sat"].get<uint8_t>(); | |
| 204 | 204 | if (!light.setColorRGB(r, g, b, 1)) |
| 205 | 205 | { |
| 206 | 206 | return false; |
| ... | ... | @@ -223,8 +223,8 @@ bool ExtendedColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLigh |
| 223 | 223 | } |
| 224 | 224 | else if (cType == "xy") |
| 225 | 225 | { |
| 226 | - float oldX = light.state["state"]["xy"][0]; | |
| 227 | - float oldY = light.state["state"]["xy"][1]; | |
| 226 | + float oldX = light.state["state"]["xy"][0].get<float>(); | |
| 227 | + float oldY = light.state["state"]["xy"][1].get<float>(); | |
| 228 | 228 | if (!light.setColorRGB(r, g, b, 1)) |
| 229 | 229 | { |
| 230 | 230 | return false; |
| ... | ... | @@ -247,7 +247,7 @@ bool ExtendedColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLigh |
| 247 | 247 | } |
| 248 | 248 | else if (cType == "ct") |
| 249 | 249 | { |
| 250 | - uint16_t oldCT = light.state["state"]["ct"]; | |
| 250 | + uint16_t oldCT = light.state["state"]["ct"].get<uint16_t>(); | |
| 251 | 251 | if (!light.setColorRGB(r, g, b, 1)) |
| 252 | 252 | { |
| 253 | 253 | return false; | ... | ... |
hueplusplus/ExtendedColorTemperatureStrategy.cpp
| ... | ... | @@ -71,12 +71,12 @@ bool ExtendedColorTemperatureStrategy::setColorTemperature( |
| 71 | 71 | bool ExtendedColorTemperatureStrategy::alertTemperature(unsigned int mired, HueLight& light) const |
| 72 | 72 | { |
| 73 | 73 | light.refreshState(); |
| 74 | - std::string cType = light.state["state"]["colormode"]; | |
| 75 | - bool on = light.state["state"]["on"]; | |
| 74 | + std::string cType = light.state["state"]["colormode"].get<std::string>(); | |
| 75 | + bool on = light.state["state"]["on"].get<bool>(); | |
| 76 | 76 | if (cType == "hs") |
| 77 | 77 | { |
| 78 | - uint16_t oldHue = light.state["state"]["hue"]; | |
| 79 | - uint8_t oldSat = light.state["state"]["sat"]; | |
| 78 | + uint16_t oldHue = light.state["state"]["hue"].get<uint16_t>(); | |
| 79 | + uint8_t oldSat = light.state["state"]["sat"].get<uint8_t>(); | |
| 80 | 80 | if (!light.setColorTemperature(mired, 1)) |
| 81 | 81 | { |
| 82 | 82 | return false; |
| ... | ... | @@ -99,8 +99,8 @@ bool ExtendedColorTemperatureStrategy::alertTemperature(unsigned int mired, HueL |
| 99 | 99 | } |
| 100 | 100 | else if (cType == "xy") |
| 101 | 101 | { |
| 102 | - float oldX = light.state["state"]["xy"][0]; | |
| 103 | - float oldY = light.state["state"]["xy"][1]; | |
| 102 | + float oldX = light.state["state"]["xy"][0].get<float>(); | |
| 103 | + float oldY = light.state["state"]["xy"][1].get<float>(); | |
| 104 | 104 | if (!light.setColorTemperature(mired, 1)) |
| 105 | 105 | { |
| 106 | 106 | return false; |
| ... | ... | @@ -123,7 +123,7 @@ bool ExtendedColorTemperatureStrategy::alertTemperature(unsigned int mired, HueL |
| 123 | 123 | } |
| 124 | 124 | else if (cType == "ct") |
| 125 | 125 | { |
| 126 | - uint16_t oldCT = light.state["state"]["ct"]; | |
| 126 | + uint16_t oldCT = light.state["state"]["ct"].get<uint16_t>(); | |
| 127 | 127 | if (!light.setColorTemperature(mired, 1)) |
| 128 | 128 | { |
| 129 | 129 | return false; | ... | ... |
hueplusplus/Hue.cpp
| ... | ... | @@ -183,7 +183,7 @@ std::string Hue::requestUsername() |
| 183 | 183 | if (jsonUser != nullptr) |
| 184 | 184 | { |
| 185 | 185 | // [{"success":{"username": "<username>"}}] |
| 186 | - username = jsonUser; | |
| 186 | + username = jsonUser.get<std::string>(); | |
| 187 | 187 | // Update commands with new username and ip |
| 188 | 188 | commands = HueCommandAPI(ip, port, username, http_handler); |
| 189 | 189 | std::cout << "Success! Link button was pressed!\n"; |
| ... | ... | @@ -235,7 +235,7 @@ HueLight& Hue::getLight(int id) |
| 235 | 235 | throw HueException(CURRENT_FILE_INFO, "Light id is not valid"); |
| 236 | 236 | } |
| 237 | 237 | // std::cout << state["lights"][std::to_string(id)] << std::endl; |
| 238 | - std::string type = state["lights"][std::to_string(id)]["modelid"]; | |
| 238 | + std::string type = state["lights"][std::to_string(id)]["modelid"].get<std::string>(); | |
| 239 | 239 | // std::cout << type << std::endl; |
| 240 | 240 | if (type == "LCT001" || type == "LCT002" || type == "LCT003" || type == "LCT007" || type == "LLM001") |
| 241 | 241 | { | ... | ... |
hueplusplus/HueLight.cpp
| ... | ... | @@ -45,12 +45,12 @@ bool HueLight::Off(uint8_t transition) |
| 45 | 45 | bool HueLight::isOn() |
| 46 | 46 | { |
| 47 | 47 | refreshState(); |
| 48 | - return state["state"]["on"]; | |
| 48 | + return state["state"]["on"].get<bool>(); | |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | bool HueLight::isOn() const |
| 52 | 52 | { |
| 53 | - return state["state"]["on"]; | |
| 53 | + return state["state"]["on"].get<bool>(); | |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | int HueLight::getId() const |
| ... | ... | @@ -60,30 +60,30 @@ int HueLight::getId() const |
| 60 | 60 | |
| 61 | 61 | std::string HueLight::getType() const |
| 62 | 62 | { |
| 63 | - return state["type"]; | |
| 63 | + return state["type"].get<std::string>(); | |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | std::string HueLight::getName() |
| 67 | 67 | { |
| 68 | 68 | refreshState(); |
| 69 | - return state["name"]; | |
| 69 | + return state["name"].get<std::string>(); | |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | std::string HueLight::getName() const |
| 73 | 73 | { |
| 74 | - return state["name"]; | |
| 74 | + return state["name"].get<std::string>(); | |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | std::string HueLight::getModelId() const |
| 78 | 78 | { |
| 79 | - return state["modelid"]; | |
| 79 | + return state["modelid"].get<std::string>(); | |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | std::string HueLight::getUId() const |
| 83 | 83 | { |
| 84 | 84 | if (state.count("uniqueid")) |
| 85 | 85 | { |
| 86 | - return state["uniqueid"]; | |
| 86 | + return state["uniqueid"].get<std::string>(); | |
| 87 | 87 | } |
| 88 | 88 | return std::string(); |
| 89 | 89 | } |
| ... | ... | @@ -92,7 +92,7 @@ std::string HueLight::getManufacturername() const |
| 92 | 92 | { |
| 93 | 93 | if (state.count("manufacturername")) |
| 94 | 94 | { |
| 95 | - return state["manufacturername"]; | |
| 95 | + return state["manufacturername"].get<std::string>(); | |
| 96 | 96 | } |
| 97 | 97 | return std::string(); |
| 98 | 98 | } |
| ... | ... | @@ -101,7 +101,7 @@ std::string HueLight::getProductname() const |
| 101 | 101 | { |
| 102 | 102 | if (state.count("productname")) |
| 103 | 103 | { |
| 104 | - return state["productname"]; | |
| 104 | + return state["productname"].get<std::string>(); | |
| 105 | 105 | } |
| 106 | 106 | return std::string(); |
| 107 | 107 | } |
| ... | ... | @@ -110,7 +110,7 @@ std::string HueLight::getLuminaireUId() const |
| 110 | 110 | { |
| 111 | 111 | if (state.count("luminaireuniqueid")) |
| 112 | 112 | { |
| 113 | - return state["luminaireuniqueid"]; | |
| 113 | + return state["luminaireuniqueid"].get<std::string>(); | |
| 114 | 114 | } |
| 115 | 115 | return std::string(); |
| 116 | 116 | } |
| ... | ... | @@ -118,12 +118,12 @@ std::string HueLight::getLuminaireUId() const |
| 118 | 118 | std::string HueLight::getSwVersion() |
| 119 | 119 | { |
| 120 | 120 | refreshState(); |
| 121 | - return state["swversion"]; | |
| 121 | + return state["swversion"].get<std::string>(); | |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | std::string HueLight::getSwVersion() const |
| 125 | 125 | { |
| 126 | - return state["swversion"]; | |
| 126 | + return state["swversion"].get<std::string>(); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | bool HueLight::setName(const std::string& name) | ... | ... |
hueplusplus/SimpleBrightnessStrategy.cpp
| ... | ... | @@ -79,10 +79,10 @@ bool SimpleBrightnessStrategy::setBrightness(unsigned int bri, uint8_t transitio |
| 79 | 79 | unsigned int SimpleBrightnessStrategy::getBrightness(HueLight& light) const |
| 80 | 80 | { |
| 81 | 81 | light.refreshState(); |
| 82 | - return light.state["state"]["bri"]; | |
| 82 | + return light.state["state"]["bri"].get<unsigned int>(); | |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | unsigned int SimpleBrightnessStrategy::getBrightness(const HueLight& light) const |
| 86 | 86 | { |
| 87 | - return light.state["state"]["bri"]; | |
| 87 | + return light.state["state"]["bri"].get<unsigned int>(); | |
| 88 | 88 | } | ... | ... |
hueplusplus/SimpleColorHueStrategy.cpp
| ... | ... | @@ -221,12 +221,12 @@ bool SimpleColorHueStrategy::setColorLoop(bool on, HueLight& light) const |
| 221 | 221 | bool SimpleColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const |
| 222 | 222 | { |
| 223 | 223 | light.refreshState(); |
| 224 | - std::string cType = light.state["state"]["colormode"]; | |
| 225 | - bool on = light.state["state"]["on"]; | |
| 224 | + std::string cType = light.state["state"]["colormode"].get<std::string>(); | |
| 225 | + bool on = light.state["state"]["on"].get<bool>(); | |
| 226 | 226 | if (cType == "hs") |
| 227 | 227 | { |
| 228 | - uint16_t oldHue = light.state["state"]["hue"]; | |
| 229 | - uint8_t oldSat = light.state["state"]["sat"]; | |
| 228 | + uint16_t oldHue = light.state["state"]["hue"].get<uint16_t>(); | |
| 229 | + uint8_t oldSat = light.state["state"]["sat"].get<uint8_t>(); | |
| 230 | 230 | if (!light.setColorHueSaturation(hue, sat, 1)) |
| 231 | 231 | { |
| 232 | 232 | return false; |
| ... | ... | @@ -249,8 +249,8 @@ bool SimpleColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, HueLi |
| 249 | 249 | } |
| 250 | 250 | else if (cType == "xy") |
| 251 | 251 | { |
| 252 | - float oldX = light.state["state"]["xy"][0]; | |
| 253 | - float oldY = light.state["state"]["xy"][1]; | |
| 252 | + float oldX = light.state["state"]["xy"][0].get<float>(); | |
| 253 | + float oldY = light.state["state"]["xy"][1].get<float>(); | |
| 254 | 254 | if (!light.setColorHueSaturation(hue, sat, 1)) |
| 255 | 255 | { |
| 256 | 256 | return false; |
| ... | ... | @@ -280,12 +280,12 @@ bool SimpleColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, HueLi |
| 280 | 280 | bool SimpleColorHueStrategy::alertXY(float x, float y, HueLight& light) const |
| 281 | 281 | { |
| 282 | 282 | light.refreshState(); |
| 283 | - std::string cType = light.state["state"]["colormode"]; | |
| 284 | - bool on = light.state["state"]["on"]; | |
| 283 | + std::string cType = light.state["state"]["colormode"].get<std::string>(); | |
| 284 | + bool on = light.state["state"]["on"].get<bool>(); | |
| 285 | 285 | if (cType == "hs") |
| 286 | 286 | { |
| 287 | - uint16_t oldHue = light.state["state"]["hue"]; | |
| 288 | - uint8_t oldSat = light.state["state"]["sat"]; | |
| 287 | + uint16_t oldHue = light.state["state"]["hue"].get<uint16_t>(); | |
| 288 | + uint8_t oldSat = light.state["state"]["sat"].get<uint8_t>(); | |
| 289 | 289 | if (!light.setColorXY(x, y, 1)) |
| 290 | 290 | { |
| 291 | 291 | return false; |
| ... | ... | @@ -308,8 +308,8 @@ bool SimpleColorHueStrategy::alertXY(float x, float y, HueLight& light) const |
| 308 | 308 | } |
| 309 | 309 | else if (cType == "xy") |
| 310 | 310 | { |
| 311 | - float oldX = light.state["state"]["xy"][0]; | |
| 312 | - float oldY = light.state["state"]["xy"][1]; | |
| 311 | + float oldX = light.state["state"]["xy"][0].get<float>(); | |
| 312 | + float oldY = light.state["state"]["xy"][1].get<float>(); | |
| 313 | 313 | if (!light.setColorXY(x, y, 1)) |
| 314 | 314 | { |
| 315 | 315 | return false; |
| ... | ... | @@ -339,12 +339,12 @@ bool SimpleColorHueStrategy::alertXY(float x, float y, HueLight& light) const |
| 339 | 339 | bool SimpleColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const |
| 340 | 340 | { |
| 341 | 341 | light.refreshState(); |
| 342 | - std::string cType = light.state["state"]["colormode"]; | |
| 343 | - bool on = light.state["state"]["on"]; | |
| 342 | + std::string cType = light.state["state"]["colormode"].get<std::string>(); | |
| 343 | + bool on = light.state["state"]["on"].get<bool>(); | |
| 344 | 344 | if (cType == "hs") |
| 345 | 345 | { |
| 346 | - uint16_t oldHue = light.state["state"]["hue"]; | |
| 347 | - uint8_t oldSat = light.state["state"]["sat"]; | |
| 346 | + uint16_t oldHue = light.state["state"]["hue"].get<uint16_t>(); | |
| 347 | + uint8_t oldSat = light.state["state"]["sat"].get<uint8_t>(); | |
| 348 | 348 | if (!light.setColorRGB(r, g, b, 1)) |
| 349 | 349 | { |
| 350 | 350 | return false; |
| ... | ... | @@ -367,8 +367,8 @@ bool SimpleColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& |
| 367 | 367 | } |
| 368 | 368 | else if (cType == "xy") |
| 369 | 369 | { |
| 370 | - float oldX = light.state["state"]["xy"][0]; | |
| 371 | - float oldY = light.state["state"]["xy"][1]; | |
| 370 | + float oldX = light.state["state"]["xy"][0].get<float>(); | |
| 371 | + float oldY = light.state["state"]["xy"][1].get<float>(); | |
| 372 | 372 | if (!light.setColorRGB(r, g, b, 1)) |
| 373 | 373 | { |
| 374 | 374 | return false; |
| ... | ... | @@ -398,25 +398,23 @@ bool SimpleColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& |
| 398 | 398 | std::pair<uint16_t, uint8_t> SimpleColorHueStrategy::getColorHueSaturation(HueLight& light) const |
| 399 | 399 | { |
| 400 | 400 | light.refreshState(); |
| 401 | - return std::pair<uint16_t, uint8_t>( | |
| 402 | - static_cast<uint16_t>(light.state["state"]["hue"]), static_cast<uint8_t>(light.state["state"]["sat"])); | |
| 401 | + return std::make_pair(light.state["state"]["hue"].get<uint16_t>(), light.state["state"]["sat"].get<uint8_t>()); | |
| 403 | 402 | } |
| 404 | 403 | |
| 405 | 404 | std::pair<uint16_t, uint8_t> SimpleColorHueStrategy::getColorHueSaturation(const HueLight& light) const |
| 406 | 405 | { |
| 407 | - return std::pair<uint16_t, uint8_t>( | |
| 408 | - static_cast<uint16_t>(light.state["state"]["hue"]), static_cast<uint8_t>(light.state["state"]["sat"])); | |
| 406 | + return std::make_pair(light.state["state"]["hue"].get<uint16_t>(), light.state["state"]["sat"].get<uint8_t>()); | |
| 409 | 407 | } |
| 410 | 408 | |
| 411 | 409 | std::pair<float, float> SimpleColorHueStrategy::getColorXY(HueLight& light) const |
| 412 | 410 | { |
| 413 | 411 | light.refreshState(); |
| 414 | - return std::pair<float, float>(light.state["state"]["xy"][0], light.state["state"]["xy"][1]); | |
| 412 | + return std::make_pair(light.state["state"]["xy"][0].get<float>(), light.state["state"]["xy"][1].get<float>()); | |
| 415 | 413 | } |
| 416 | 414 | |
| 417 | 415 | std::pair<float, float> SimpleColorHueStrategy::getColorXY(const HueLight& light) const |
| 418 | 416 | { |
| 419 | - return std::pair<float, float>(light.state["state"]["xy"][0], light.state["state"]["xy"][1]); | |
| 417 | + return std::make_pair(light.state["state"]["xy"][0].get<float>(), light.state["state"]["xy"][1].get<float>()); | |
| 420 | 418 | } |
| 421 | 419 | /*bool SimpleColorHueStrategy::pointInTriangle(float pointx, float pointy, float |
| 422 | 420 | x0, float y0, float x1, float y1, float x2, float y2) | ... | ... |
hueplusplus/SimpleColorTemperatureStrategy.cpp
| ... | ... | @@ -70,11 +70,11 @@ bool SimpleColorTemperatureStrategy::setColorTemperature(unsigned int mired, uin |
| 70 | 70 | bool SimpleColorTemperatureStrategy::alertTemperature(unsigned int mired, HueLight& light) const |
| 71 | 71 | { |
| 72 | 72 | light.refreshState(); |
| 73 | - std::string cType = light.state["state"]["colormode"]; | |
| 74 | - bool on = light.state["state"]["on"]; | |
| 73 | + std::string cType = light.state["state"]["colormode"].get<std::string>(); | |
| 74 | + bool on = light.state["state"]["on"].get<bool>(); | |
| 75 | 75 | if (cType == "ct") |
| 76 | 76 | { |
| 77 | - uint16_t oldCT = light.state["state"]["ct"]; | |
| 77 | + uint16_t oldCT = light.state["state"]["ct"].get<uint16_t>(); | |
| 78 | 78 | if (!light.setColorTemperature(mired, 1)) |
| 79 | 79 | { |
| 80 | 80 | return false; |
| ... | ... | @@ -104,10 +104,10 @@ bool SimpleColorTemperatureStrategy::alertTemperature(unsigned int mired, HueLig |
| 104 | 104 | unsigned int SimpleColorTemperatureStrategy::getColorTemperature(HueLight& light) const |
| 105 | 105 | { |
| 106 | 106 | light.refreshState(); |
| 107 | - return light.state["state"]["ct"]; | |
| 107 | + return light.state["state"]["ct"].get<unsigned int>(); | |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | unsigned int SimpleColorTemperatureStrategy::getColorTemperature(const HueLight& light) const |
| 111 | 111 | { |
| 112 | - return light.state["state"]["ct"]; | |
| 112 | + return light.state["state"]["ct"].get<unsigned int>(); | |
| 113 | 113 | } | ... | ... |
hueplusplus/test/test_HueLight.cpp
| ... | ... | @@ -385,9 +385,9 @@ TEST_F(HueLightTest, setName) |
| 385 | 385 | HueLight test_light_2 = test_bridge.getLight(2); |
| 386 | 386 | HueLight test_light_3 = test_bridge.getLight(3); |
| 387 | 387 | |
| 388 | - EXPECT_EQ(true, test_light_1.setName(expected_request["name"])); | |
| 389 | - EXPECT_EQ(false, test_light_2.setName(expected_request["name"])); | |
| 390 | - EXPECT_EQ(true, test_light_3.setName(expected_request["name"])); | |
| 388 | + EXPECT_EQ(true, test_light_1.setName(expected_request["name"].get<std::string>())); | |
| 389 | + EXPECT_EQ(false, test_light_2.setName(expected_request["name"].get<std::string>())); | |
| 390 | + EXPECT_EQ(true, test_light_3.setName(expected_request["name"].get<std::string>())); | |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | 393 | TEST_F(HueLightTest, getColorType) | ... | ... |