Commit cd25b44ce8aef48e672861edabf75ade62716b27
1 parent
0dec011a
remove unneeded comments, remove const references to prevent segfaults, change n…
…aming of some variables
Showing
1 changed file
with
15 additions
and
68 deletions
hueplusplus/Hue.cpp
| @@ -49,7 +49,7 @@ std::vector<HueFinder::HueIdentification> HueFinder::FindBridges() const | @@ -49,7 +49,7 @@ std::vector<HueFinder::HueIdentification> HueFinder::FindBridges() const | ||
| 49 | std::vector<HueIdentification> foundBridges; | 49 | std::vector<HueIdentification> foundBridges; |
| 50 | for (const std::pair<std::string, std::string> &p : foundDevices) | 50 | for (const std::pair<std::string, std::string> &p : foundDevices) |
| 51 | { | 51 | { |
| 52 | - size_t found = p.second.find("IpBridge"); | 52 | + unsigned int found = p.second.find("IpBridge"); |
| 53 | if (found != std::string::npos) | 53 | if (found != std::string::npos) |
| 54 | { | 54 | { |
| 55 | HueIdentification bridge; | 55 | HueIdentification bridge; |
| @@ -165,11 +165,11 @@ Hue::Hue(const std::string& ip, const std::string& username) : | @@ -165,11 +165,11 @@ Hue::Hue(const std::string& ip, const std::string& username) : | ||
| 165 | ip(ip), | 165 | ip(ip), |
| 166 | username(username) | 166 | username(username) |
| 167 | { | 167 | { |
| 168 | - _simpleBrightnessStrategy = std::shared_ptr<BrightnessStrategy>( new SimpleBrightnessStrategy ); | ||
| 169 | - _simpleColorHueStrategy = std::shared_ptr<ColorHueStrategy>( new SimpleColorHueStrategy ); | ||
| 170 | - _extendedColorHueStrategy = std::shared_ptr<ColorHueStrategy>( new ExtendedColorHueStrategy ); | ||
| 171 | - _simpleColorTemperatureStrategy = std::shared_ptr<ColorTemperatureStrategy>( new SimpleColorTemperatureStrategy ); | ||
| 172 | - _extendedColorTemperatureStrategy = std::shared_ptr<ColorTemperatureStrategy>( new ExtendedColorTemperatureStrategy ); | 168 | + simpleBrightnessStrategy = std::make_shared<SimpleBrightnessStrategy>(); |
| 169 | + simpleColorHueStrategy = std::make_shared<SimpleColorHueStrategy>(); | ||
| 170 | + extendedColorHueStrategy = std::make_shared<ExtendedColorHueStrategy>(); | ||
| 171 | + simpleColorTemperatureStrategy = std::make_shared<SimpleColorTemperatureStrategy>(); | ||
| 172 | + extendedColorTemperatureStrategy = std::make_shared<ExtendedColorTemperatureStrategy>(); | ||
| 173 | } | 173 | } |
| 174 | 174 | ||
| 175 | std::string Hue::getBridgeIP() | 175 | std::string Hue::getBridgeIP() |
| @@ -242,7 +242,7 @@ void Hue::setIP(const std::string ip) | @@ -242,7 +242,7 @@ void Hue::setIP(const std::string ip) | ||
| 242 | this->ip = ip; | 242 | this->ip = ip; |
| 243 | } | 243 | } |
| 244 | 244 | ||
| 245 | -const HueLight& Hue::getLight(int id) | 245 | +HueLight& Hue::getLight(int id) |
| 246 | { | 246 | { |
| 247 | if(lights.count(id) > 0) | 247 | if(lights.count(id) > 0) |
| 248 | { | 248 | { |
| @@ -260,10 +260,7 @@ const HueLight& Hue::getLight(int id) | @@ -260,10 +260,7 @@ const HueLight& Hue::getLight(int id) | ||
| 260 | if (type == "LCT001" || type == "LCT002" || type == "LCT003" || type == "LCT007" || type == "LLM001") | 260 | if (type == "LCT001" || type == "LCT002" || type == "LCT003" || type == "LCT007" || type == "LLM001") |
| 261 | { | 261 | { |
| 262 | // HueExtendedColorLight Gamut B | 262 | // HueExtendedColorLight Gamut B |
| 263 | - HueLight light = HueLight(ip, username, id); | ||
| 264 | - light.setBrightnessStrategy(_simpleBrightnessStrategy); | ||
| 265 | - light.setColorHueStrategy(_extendedColorHueStrategy); | ||
| 266 | - light.setColorTemperatureStrategy(_extendedColorTemperatureStrategy); | 263 | + HueLight light = HueLight(ip, username, id, simpleBrightnessStrategy, extendedColorTemperatureStrategy, extendedColorHueStrategy); |
| 267 | light.colorType = ColorType::GAMUT_B; | 264 | light.colorType = ColorType::GAMUT_B; |
| 268 | lights.emplace(id, light); | 265 | lights.emplace(id, light); |
| 269 | return lights.find(id)->second; | 266 | return lights.find(id)->second; |
| @@ -271,10 +268,7 @@ const HueLight& Hue::getLight(int id) | @@ -271,10 +268,7 @@ const HueLight& Hue::getLight(int id) | ||
| 271 | else if (type == "LCT010" || type == "LCT011" || type == "LCT014" || type == "LLC020" || type == "LST002") | 268 | else if (type == "LCT010" || type == "LCT011" || type == "LCT014" || type == "LLC020" || type == "LST002") |
| 272 | { | 269 | { |
| 273 | // HueExtendedColorLight Gamut C | 270 | // HueExtendedColorLight Gamut C |
| 274 | - HueLight light = HueLight(ip, username, id); | ||
| 275 | - light.setBrightnessStrategy(_simpleBrightnessStrategy); | ||
| 276 | - light.setColorHueStrategy(_extendedColorHueStrategy); | ||
| 277 | - light.setColorTemperatureStrategy(_extendedColorTemperatureStrategy); | 271 | + HueLight light = HueLight(ip, username, id, simpleBrightnessStrategy, extendedColorTemperatureStrategy, extendedColorHueStrategy); |
| 278 | light.colorType = ColorType::GAMUT_C; | 272 | light.colorType = ColorType::GAMUT_C; |
| 279 | lights.emplace(id, light); | 273 | lights.emplace(id, light); |
| 280 | return lights.find(id)->second; | 274 | return lights.find(id)->second; |
| @@ -282,10 +276,7 @@ const HueLight& Hue::getLight(int id) | @@ -282,10 +276,7 @@ const HueLight& Hue::getLight(int id) | ||
| 282 | else if (type == "LST001" || type == "LLC006" || type == "LLC007" || type == "LLC010" || type == "LLC011" || type == "LLC012" || type == "LLC013") | 276 | else if (type == "LST001" || type == "LLC006" || type == "LLC007" || type == "LLC010" || type == "LLC011" || type == "LLC012" || type == "LLC013") |
| 283 | { | 277 | { |
| 284 | // HueColorLight Gamut A | 278 | // HueColorLight Gamut A |
| 285 | - HueLight light = HueLight(ip, username, id); | ||
| 286 | - light.setBrightnessStrategy(_simpleBrightnessStrategy); | ||
| 287 | - light.setColorHueStrategy(_simpleColorHueStrategy); | ||
| 288 | - light.setColorTemperatureStrategy(_simpleColorTemperatureStrategy); | 279 | + HueLight light = HueLight(ip, username, id, simpleBrightnessStrategy, simpleColorTemperatureStrategy, simpleColorHueStrategy); |
| 289 | light.colorType = ColorType::GAMUT_A; | 280 | light.colorType = ColorType::GAMUT_A; |
| 290 | lights.emplace(id, light); | 281 | lights.emplace(id, light); |
| 291 | return lights.find(id)->second; | 282 | return lights.find(id)->second; |
| @@ -293,10 +284,7 @@ const HueLight& Hue::getLight(int id) | @@ -293,10 +284,7 @@ const HueLight& Hue::getLight(int id) | ||
| 293 | else if (type == "LWB004" || type == "LWB006" || type == "LWB007" || type == "LWB010" || type == "LWB014") | 284 | else if (type == "LWB004" || type == "LWB006" || type == "LWB007" || type == "LWB010" || type == "LWB014") |
| 294 | { | 285 | { |
| 295 | // HueDimmableLight No Color Type | 286 | // HueDimmableLight No Color Type |
| 296 | - HueLight light = HueLight(ip, username, id); | ||
| 297 | - light.setBrightnessStrategy(_simpleBrightnessStrategy); | ||
| 298 | - //light.setColorHueStrategy(); | ||
| 299 | - //light.setColorTemperatureStrategy(); | 287 | + HueLight light = HueLight(ip, username, id, simpleBrightnessStrategy, nullptr, nullptr); |
| 300 | light.colorType = ColorType::NONE; | 288 | light.colorType = ColorType::NONE; |
| 301 | lights.emplace(id, light); | 289 | lights.emplace(id, light); |
| 302 | return lights.find(id)->second; | 290 | return lights.find(id)->second; |
| @@ -304,10 +292,7 @@ const HueLight& Hue::getLight(int id) | @@ -304,10 +292,7 @@ const HueLight& Hue::getLight(int id) | ||
| 304 | else if (type == "LLM010" || type == "LLM011" || type == "LLM012" || type == "LTW001" || type == "LTW004" || type == "LTW013" || type == "LTW014") | 292 | else if (type == "LLM010" || type == "LLM011" || type == "LLM012" || type == "LTW001" || type == "LTW004" || type == "LTW013" || type == "LTW014") |
| 305 | { | 293 | { |
| 306 | // HueTemperatureLight | 294 | // HueTemperatureLight |
| 307 | - HueLight light = HueLight(ip, username, id); | ||
| 308 | - light.setBrightnessStrategy(_simpleBrightnessStrategy); | ||
| 309 | - //light.setColorHueStrategy(); | ||
| 310 | - light.setColorTemperatureStrategy(_simpleColorTemperatureStrategy); | 295 | + HueLight light = HueLight(ip, username, id, simpleBrightnessStrategy, simpleColorTemperatureStrategy, nullptr); |
| 311 | light.colorType = ColorType::TEMPERATURE; | 296 | light.colorType = ColorType::TEMPERATURE; |
| 312 | lights.emplace(id, light); | 297 | lights.emplace(id, light); |
| 313 | return lights.find(id)->second; | 298 | return lights.find(id)->second; |
| @@ -316,45 +301,7 @@ const HueLight& Hue::getLight(int id) | @@ -316,45 +301,7 @@ const HueLight& Hue::getLight(int id) | ||
| 316 | throw(std::runtime_error("Could not determine HueLight type!")); | 301 | throw(std::runtime_error("Could not determine HueLight type!")); |
| 317 | } | 302 | } |
| 318 | 303 | ||
| 319 | -/*const std::map<uint8_t, ColorType>& Hue::getAllLightTypes() | ||
| 320 | -{ | ||
| 321 | - refreshState(); | ||
| 322 | - for (const auto& name : state["lights"].getMemberNames()) | ||
| 323 | - { | ||
| 324 | - std::string type = state["lights"][name]["modelid"].asString(); | ||
| 325 | - int id = std::stoi(name); | ||
| 326 | - | ||
| 327 | - if (type == "LCT001" || type == "LCT002" || type == "LCT003" || type == "LCT007" || type == "LLM001") | ||
| 328 | - { | ||
| 329 | - // HueExtendedColorLight Gamut B | ||
| 330 | - lights[id].second = ColorType::GAMUT_B; | ||
| 331 | - } | ||
| 332 | - else if (type == "LCT010" || type == "LCT011" || type == "LCT014" || type == "LLC020" || type == "LST002") | ||
| 333 | - { | ||
| 334 | - // HueExtendedColorLight Gamut C | ||
| 335 | - lights[id].second = ColorType::GAMUT_C; | ||
| 336 | - } | ||
| 337 | - else if (type == "LST001" || type == "LLC006" || type == "LLC007" || type == "LLC010" || type == "LLC011" || type == "LLC012" || type == "LLC013") | ||
| 338 | - { | ||
| 339 | - // HueColorLight Gamut A | ||
| 340 | - lights[id].second = ColorType::GAMUT_A; | ||
| 341 | - } | ||
| 342 | - else if (type == "LWB004" || type == "LWB006" || type == "LWB007" || type == "LWB010" || type == "LWB014") | ||
| 343 | - { | ||
| 344 | - // HueDimmableLight No Color Type | ||
| 345 | - lights[id].second = ColorType::NONE; | ||
| 346 | - } | ||
| 347 | - else if (type == "LLM010" || type == "LLM011" || type == "LLM012" || type == "LTW001" || type == "LTW004" || type == "LTW013" || type == "LTW014") | ||
| 348 | - { | ||
| 349 | - // HueTemperatureLight | ||
| 350 | - lights[id].second = ColorType::TEMPERATURE; | ||
| 351 | - } | ||
| 352 | - } | ||
| 353 | - return lights; | ||
| 354 | -}*/ | ||
| 355 | - | ||
| 356 | - | ||
| 357 | -std::vector<std::reference_wrapper<const HueLight>> Hue::getAllLights() | 304 | +std::vector<std::reference_wrapper<HueLight>> Hue::getAllLights() |
| 358 | { | 305 | { |
| 359 | refreshState(); | 306 | refreshState(); |
| 360 | for (const auto& name : state["lights"].getMemberNames()) | 307 | for (const auto& name : state["lights"].getMemberNames()) |
| @@ -365,8 +312,8 @@ std::vector<std::reference_wrapper<const HueLight>> Hue::getAllLights() | @@ -365,8 +312,8 @@ std::vector<std::reference_wrapper<const HueLight>> Hue::getAllLights() | ||
| 365 | getLight(id); | 312 | getLight(id); |
| 366 | } | 313 | } |
| 367 | } | 314 | } |
| 368 | - std::vector<std::reference_wrapper<const HueLight>> result; | ||
| 369 | - for (const auto& entry : lights) | 315 | + std::vector<std::reference_wrapper<HueLight>> result; |
| 316 | + for (auto& entry : lights) | ||
| 370 | { | 317 | { |
| 371 | result.emplace_back(entry.second); | 318 | result.emplace_back(entry.second); |
| 372 | } | 319 | } |