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,12 +31,12 @@ | ||
| 31 | bool ExtendedColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const | 31 | bool ExtendedColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const |
| 32 | { | 32 | { |
| 33 | light.refreshState(); | 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 | if (cType == "hs") | 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 | if (!light.setColorHueSaturation(hue, sat, 1)) | 40 | if (!light.setColorHueSaturation(hue, sat, 1)) |
| 41 | { | 41 | { |
| 42 | return false; | 42 | return false; |
| @@ -59,8 +59,8 @@ bool ExtendedColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, Hue | @@ -59,8 +59,8 @@ bool ExtendedColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, Hue | ||
| 59 | } | 59 | } |
| 60 | else if (cType == "xy") | 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 | if (!light.setColorHueSaturation(hue, sat, 1)) | 64 | if (!light.setColorHueSaturation(hue, sat, 1)) |
| 65 | { | 65 | { |
| 66 | return false; | 66 | return false; |
| @@ -83,7 +83,7 @@ bool ExtendedColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, Hue | @@ -83,7 +83,7 @@ bool ExtendedColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, Hue | ||
| 83 | } | 83 | } |
| 84 | else if (cType == "ct") | 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 | if (!light.setColorHueSaturation(hue, sat, 1)) | 87 | if (!light.setColorHueSaturation(hue, sat, 1)) |
| 88 | { | 88 | { |
| 89 | return false; | 89 | return false; |
| @@ -113,12 +113,12 @@ bool ExtendedColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, Hue | @@ -113,12 +113,12 @@ bool ExtendedColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, Hue | ||
| 113 | bool ExtendedColorHueStrategy::alertXY(float x, float y, HueLight& light) const | 113 | bool ExtendedColorHueStrategy::alertXY(float x, float y, HueLight& light) const |
| 114 | { | 114 | { |
| 115 | light.refreshState(); | 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 | if (cType == "hs") | 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 | if (!light.setColorXY(x, y, 1)) | 122 | if (!light.setColorXY(x, y, 1)) |
| 123 | { | 123 | { |
| 124 | return false; | 124 | return false; |
| @@ -141,8 +141,8 @@ bool ExtendedColorHueStrategy::alertXY(float x, float y, HueLight& light) const | @@ -141,8 +141,8 @@ bool ExtendedColorHueStrategy::alertXY(float x, float y, HueLight& light) const | ||
| 141 | } | 141 | } |
| 142 | else if (cType == "xy") | 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 | if (!light.setColorXY(x, y, 1)) | 146 | if (!light.setColorXY(x, y, 1)) |
| 147 | { | 147 | { |
| 148 | return false; | 148 | return false; |
| @@ -165,7 +165,7 @@ bool ExtendedColorHueStrategy::alertXY(float x, float y, HueLight& light) const | @@ -165,7 +165,7 @@ bool ExtendedColorHueStrategy::alertXY(float x, float y, HueLight& light) const | ||
| 165 | } | 165 | } |
| 166 | else if (cType == "ct") | 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 | if (!light.setColorXY(x, y, 1)) | 169 | if (!light.setColorXY(x, y, 1)) |
| 170 | { | 170 | { |
| 171 | return false; | 171 | return false; |
| @@ -195,12 +195,12 @@ bool ExtendedColorHueStrategy::alertXY(float x, float y, HueLight& light) const | @@ -195,12 +195,12 @@ bool ExtendedColorHueStrategy::alertXY(float x, float y, HueLight& light) const | ||
| 195 | bool ExtendedColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const | 195 | bool ExtendedColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const |
| 196 | { | 196 | { |
| 197 | light.refreshState(); | 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 | if (cType == "hs") | 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 | if (!light.setColorRGB(r, g, b, 1)) | 204 | if (!light.setColorRGB(r, g, b, 1)) |
| 205 | { | 205 | { |
| 206 | return false; | 206 | return false; |
| @@ -223,8 +223,8 @@ bool ExtendedColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLigh | @@ -223,8 +223,8 @@ bool ExtendedColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLigh | ||
| 223 | } | 223 | } |
| 224 | else if (cType == "xy") | 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 | if (!light.setColorRGB(r, g, b, 1)) | 228 | if (!light.setColorRGB(r, g, b, 1)) |
| 229 | { | 229 | { |
| 230 | return false; | 230 | return false; |
| @@ -247,7 +247,7 @@ bool ExtendedColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLigh | @@ -247,7 +247,7 @@ bool ExtendedColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLigh | ||
| 247 | } | 247 | } |
| 248 | else if (cType == "ct") | 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 | if (!light.setColorRGB(r, g, b, 1)) | 251 | if (!light.setColorRGB(r, g, b, 1)) |
| 252 | { | 252 | { |
| 253 | return false; | 253 | return false; |
hueplusplus/ExtendedColorTemperatureStrategy.cpp
| @@ -71,12 +71,12 @@ bool ExtendedColorTemperatureStrategy::setColorTemperature( | @@ -71,12 +71,12 @@ bool ExtendedColorTemperatureStrategy::setColorTemperature( | ||
| 71 | bool ExtendedColorTemperatureStrategy::alertTemperature(unsigned int mired, HueLight& light) const | 71 | bool ExtendedColorTemperatureStrategy::alertTemperature(unsigned int mired, HueLight& light) const |
| 72 | { | 72 | { |
| 73 | light.refreshState(); | 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 | if (cType == "hs") | 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 | if (!light.setColorTemperature(mired, 1)) | 80 | if (!light.setColorTemperature(mired, 1)) |
| 81 | { | 81 | { |
| 82 | return false; | 82 | return false; |
| @@ -99,8 +99,8 @@ bool ExtendedColorTemperatureStrategy::alertTemperature(unsigned int mired, HueL | @@ -99,8 +99,8 @@ bool ExtendedColorTemperatureStrategy::alertTemperature(unsigned int mired, HueL | ||
| 99 | } | 99 | } |
| 100 | else if (cType == "xy") | 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 | if (!light.setColorTemperature(mired, 1)) | 104 | if (!light.setColorTemperature(mired, 1)) |
| 105 | { | 105 | { |
| 106 | return false; | 106 | return false; |
| @@ -123,7 +123,7 @@ bool ExtendedColorTemperatureStrategy::alertTemperature(unsigned int mired, HueL | @@ -123,7 +123,7 @@ bool ExtendedColorTemperatureStrategy::alertTemperature(unsigned int mired, HueL | ||
| 123 | } | 123 | } |
| 124 | else if (cType == "ct") | 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 | if (!light.setColorTemperature(mired, 1)) | 127 | if (!light.setColorTemperature(mired, 1)) |
| 128 | { | 128 | { |
| 129 | return false; | 129 | return false; |
hueplusplus/Hue.cpp
| @@ -183,7 +183,7 @@ std::string Hue::requestUsername() | @@ -183,7 +183,7 @@ std::string Hue::requestUsername() | ||
| 183 | if (jsonUser != nullptr) | 183 | if (jsonUser != nullptr) |
| 184 | { | 184 | { |
| 185 | // [{"success":{"username": "<username>"}}] | 185 | // [{"success":{"username": "<username>"}}] |
| 186 | - username = jsonUser; | 186 | + username = jsonUser.get<std::string>(); |
| 187 | // Update commands with new username and ip | 187 | // Update commands with new username and ip |
| 188 | commands = HueCommandAPI(ip, port, username, http_handler); | 188 | commands = HueCommandAPI(ip, port, username, http_handler); |
| 189 | std::cout << "Success! Link button was pressed!\n"; | 189 | std::cout << "Success! Link button was pressed!\n"; |
| @@ -235,7 +235,7 @@ HueLight& Hue::getLight(int id) | @@ -235,7 +235,7 @@ HueLight& Hue::getLight(int id) | ||
| 235 | throw HueException(CURRENT_FILE_INFO, "Light id is not valid"); | 235 | throw HueException(CURRENT_FILE_INFO, "Light id is not valid"); |
| 236 | } | 236 | } |
| 237 | // std::cout << state["lights"][std::to_string(id)] << std::endl; | 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 | // std::cout << type << std::endl; | 239 | // std::cout << type << std::endl; |
| 240 | if (type == "LCT001" || type == "LCT002" || type == "LCT003" || type == "LCT007" || type == "LLM001") | 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,12 +45,12 @@ bool HueLight::Off(uint8_t transition) | ||
| 45 | bool HueLight::isOn() | 45 | bool HueLight::isOn() |
| 46 | { | 46 | { |
| 47 | refreshState(); | 47 | refreshState(); |
| 48 | - return state["state"]["on"]; | 48 | + return state["state"]["on"].get<bool>(); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | bool HueLight::isOn() const | 51 | bool HueLight::isOn() const |
| 52 | { | 52 | { |
| 53 | - return state["state"]["on"]; | 53 | + return state["state"]["on"].get<bool>(); |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | int HueLight::getId() const | 56 | int HueLight::getId() const |
| @@ -60,30 +60,30 @@ int HueLight::getId() const | @@ -60,30 +60,30 @@ int HueLight::getId() const | ||
| 60 | 60 | ||
| 61 | std::string HueLight::getType() const | 61 | std::string HueLight::getType() const |
| 62 | { | 62 | { |
| 63 | - return state["type"]; | 63 | + return state["type"].get<std::string>(); |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | std::string HueLight::getName() | 66 | std::string HueLight::getName() |
| 67 | { | 67 | { |
| 68 | refreshState(); | 68 | refreshState(); |
| 69 | - return state["name"]; | 69 | + return state["name"].get<std::string>(); |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | std::string HueLight::getName() const | 72 | std::string HueLight::getName() const |
| 73 | { | 73 | { |
| 74 | - return state["name"]; | 74 | + return state["name"].get<std::string>(); |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | std::string HueLight::getModelId() const | 77 | std::string HueLight::getModelId() const |
| 78 | { | 78 | { |
| 79 | - return state["modelid"]; | 79 | + return state["modelid"].get<std::string>(); |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | std::string HueLight::getUId() const | 82 | std::string HueLight::getUId() const |
| 83 | { | 83 | { |
| 84 | if (state.count("uniqueid")) | 84 | if (state.count("uniqueid")) |
| 85 | { | 85 | { |
| 86 | - return state["uniqueid"]; | 86 | + return state["uniqueid"].get<std::string>(); |
| 87 | } | 87 | } |
| 88 | return std::string(); | 88 | return std::string(); |
| 89 | } | 89 | } |
| @@ -92,7 +92,7 @@ std::string HueLight::getManufacturername() const | @@ -92,7 +92,7 @@ std::string HueLight::getManufacturername() const | ||
| 92 | { | 92 | { |
| 93 | if (state.count("manufacturername")) | 93 | if (state.count("manufacturername")) |
| 94 | { | 94 | { |
| 95 | - return state["manufacturername"]; | 95 | + return state["manufacturername"].get<std::string>(); |
| 96 | } | 96 | } |
| 97 | return std::string(); | 97 | return std::string(); |
| 98 | } | 98 | } |
| @@ -101,7 +101,7 @@ std::string HueLight::getProductname() const | @@ -101,7 +101,7 @@ std::string HueLight::getProductname() const | ||
| 101 | { | 101 | { |
| 102 | if (state.count("productname")) | 102 | if (state.count("productname")) |
| 103 | { | 103 | { |
| 104 | - return state["productname"]; | 104 | + return state["productname"].get<std::string>(); |
| 105 | } | 105 | } |
| 106 | return std::string(); | 106 | return std::string(); |
| 107 | } | 107 | } |
| @@ -110,7 +110,7 @@ std::string HueLight::getLuminaireUId() const | @@ -110,7 +110,7 @@ std::string HueLight::getLuminaireUId() const | ||
| 110 | { | 110 | { |
| 111 | if (state.count("luminaireuniqueid")) | 111 | if (state.count("luminaireuniqueid")) |
| 112 | { | 112 | { |
| 113 | - return state["luminaireuniqueid"]; | 113 | + return state["luminaireuniqueid"].get<std::string>(); |
| 114 | } | 114 | } |
| 115 | return std::string(); | 115 | return std::string(); |
| 116 | } | 116 | } |
| @@ -118,12 +118,12 @@ std::string HueLight::getLuminaireUId() const | @@ -118,12 +118,12 @@ std::string HueLight::getLuminaireUId() const | ||
| 118 | std::string HueLight::getSwVersion() | 118 | std::string HueLight::getSwVersion() |
| 119 | { | 119 | { |
| 120 | refreshState(); | 120 | refreshState(); |
| 121 | - return state["swversion"]; | 121 | + return state["swversion"].get<std::string>(); |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | std::string HueLight::getSwVersion() const | 124 | std::string HueLight::getSwVersion() const |
| 125 | { | 125 | { |
| 126 | - return state["swversion"]; | 126 | + return state["swversion"].get<std::string>(); |
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | bool HueLight::setName(const std::string& name) | 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,10 +79,10 @@ bool SimpleBrightnessStrategy::setBrightness(unsigned int bri, uint8_t transitio | ||
| 79 | unsigned int SimpleBrightnessStrategy::getBrightness(HueLight& light) const | 79 | unsigned int SimpleBrightnessStrategy::getBrightness(HueLight& light) const |
| 80 | { | 80 | { |
| 81 | light.refreshState(); | 81 | light.refreshState(); |
| 82 | - return light.state["state"]["bri"]; | 82 | + return light.state["state"]["bri"].get<unsigned int>(); |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | unsigned int SimpleBrightnessStrategy::getBrightness(const HueLight& light) const | 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,12 +221,12 @@ bool SimpleColorHueStrategy::setColorLoop(bool on, HueLight& light) const | ||
| 221 | bool SimpleColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const | 221 | bool SimpleColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const |
| 222 | { | 222 | { |
| 223 | light.refreshState(); | 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 | if (cType == "hs") | 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 | if (!light.setColorHueSaturation(hue, sat, 1)) | 230 | if (!light.setColorHueSaturation(hue, sat, 1)) |
| 231 | { | 231 | { |
| 232 | return false; | 232 | return false; |
| @@ -249,8 +249,8 @@ bool SimpleColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, HueLi | @@ -249,8 +249,8 @@ bool SimpleColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, HueLi | ||
| 249 | } | 249 | } |
| 250 | else if (cType == "xy") | 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 | if (!light.setColorHueSaturation(hue, sat, 1)) | 254 | if (!light.setColorHueSaturation(hue, sat, 1)) |
| 255 | { | 255 | { |
| 256 | return false; | 256 | return false; |
| @@ -280,12 +280,12 @@ bool SimpleColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, HueLi | @@ -280,12 +280,12 @@ bool SimpleColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, HueLi | ||
| 280 | bool SimpleColorHueStrategy::alertXY(float x, float y, HueLight& light) const | 280 | bool SimpleColorHueStrategy::alertXY(float x, float y, HueLight& light) const |
| 281 | { | 281 | { |
| 282 | light.refreshState(); | 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 | if (cType == "hs") | 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 | if (!light.setColorXY(x, y, 1)) | 289 | if (!light.setColorXY(x, y, 1)) |
| 290 | { | 290 | { |
| 291 | return false; | 291 | return false; |
| @@ -308,8 +308,8 @@ bool SimpleColorHueStrategy::alertXY(float x, float y, HueLight& light) const | @@ -308,8 +308,8 @@ bool SimpleColorHueStrategy::alertXY(float x, float y, HueLight& light) const | ||
| 308 | } | 308 | } |
| 309 | else if (cType == "xy") | 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 | if (!light.setColorXY(x, y, 1)) | 313 | if (!light.setColorXY(x, y, 1)) |
| 314 | { | 314 | { |
| 315 | return false; | 315 | return false; |
| @@ -339,12 +339,12 @@ bool SimpleColorHueStrategy::alertXY(float x, float y, HueLight& light) const | @@ -339,12 +339,12 @@ bool SimpleColorHueStrategy::alertXY(float x, float y, HueLight& light) const | ||
| 339 | bool SimpleColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const | 339 | bool SimpleColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const |
| 340 | { | 340 | { |
| 341 | light.refreshState(); | 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 | if (cType == "hs") | 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 | if (!light.setColorRGB(r, g, b, 1)) | 348 | if (!light.setColorRGB(r, g, b, 1)) |
| 349 | { | 349 | { |
| 350 | return false; | 350 | return false; |
| @@ -367,8 +367,8 @@ bool SimpleColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& | @@ -367,8 +367,8 @@ bool SimpleColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& | ||
| 367 | } | 367 | } |
| 368 | else if (cType == "xy") | 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 | if (!light.setColorRGB(r, g, b, 1)) | 372 | if (!light.setColorRGB(r, g, b, 1)) |
| 373 | { | 373 | { |
| 374 | return false; | 374 | return false; |
| @@ -398,25 +398,23 @@ bool SimpleColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& | @@ -398,25 +398,23 @@ bool SimpleColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& | ||
| 398 | std::pair<uint16_t, uint8_t> SimpleColorHueStrategy::getColorHueSaturation(HueLight& light) const | 398 | std::pair<uint16_t, uint8_t> SimpleColorHueStrategy::getColorHueSaturation(HueLight& light) const |
| 399 | { | 399 | { |
| 400 | light.refreshState(); | 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 | std::pair<uint16_t, uint8_t> SimpleColorHueStrategy::getColorHueSaturation(const HueLight& light) const | 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 | std::pair<float, float> SimpleColorHueStrategy::getColorXY(HueLight& light) const | 409 | std::pair<float, float> SimpleColorHueStrategy::getColorXY(HueLight& light) const |
| 412 | { | 410 | { |
| 413 | light.refreshState(); | 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 | std::pair<float, float> SimpleColorHueStrategy::getColorXY(const HueLight& light) const | 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 | /*bool SimpleColorHueStrategy::pointInTriangle(float pointx, float pointy, float | 419 | /*bool SimpleColorHueStrategy::pointInTriangle(float pointx, float pointy, float |
| 422 | x0, float y0, float x1, float y1, float x2, float y2) | 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,11 +70,11 @@ bool SimpleColorTemperatureStrategy::setColorTemperature(unsigned int mired, uin | ||
| 70 | bool SimpleColorTemperatureStrategy::alertTemperature(unsigned int mired, HueLight& light) const | 70 | bool SimpleColorTemperatureStrategy::alertTemperature(unsigned int mired, HueLight& light) const |
| 71 | { | 71 | { |
| 72 | light.refreshState(); | 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 | if (cType == "ct") | 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 | if (!light.setColorTemperature(mired, 1)) | 78 | if (!light.setColorTemperature(mired, 1)) |
| 79 | { | 79 | { |
| 80 | return false; | 80 | return false; |
| @@ -104,10 +104,10 @@ bool SimpleColorTemperatureStrategy::alertTemperature(unsigned int mired, HueLig | @@ -104,10 +104,10 @@ bool SimpleColorTemperatureStrategy::alertTemperature(unsigned int mired, HueLig | ||
| 104 | unsigned int SimpleColorTemperatureStrategy::getColorTemperature(HueLight& light) const | 104 | unsigned int SimpleColorTemperatureStrategy::getColorTemperature(HueLight& light) const |
| 105 | { | 105 | { |
| 106 | light.refreshState(); | 106 | light.refreshState(); |
| 107 | - return light.state["state"]["ct"]; | 107 | + return light.state["state"]["ct"].get<unsigned int>(); |
| 108 | } | 108 | } |
| 109 | 109 | ||
| 110 | unsigned int SimpleColorTemperatureStrategy::getColorTemperature(const HueLight& light) const | 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,9 +385,9 @@ TEST_F(HueLightTest, setName) | ||
| 385 | HueLight test_light_2 = test_bridge.getLight(2); | 385 | HueLight test_light_2 = test_bridge.getLight(2); |
| 386 | HueLight test_light_3 = test_bridge.getLight(3); | 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 | TEST_F(HueLightTest, getColorType) | 393 | TEST_F(HueLightTest, getColorType) |