Commit 63f09522e316e40649183e4bc602693c1fe766c7
Committed by
Jan
1 parent
dd412fe1
Add new lighttypes
Showing
60 changed files
with
322 additions
and
377 deletions
.codecov.yml
100644 → 100755
.gitignore
100644 → 100755
.travis.yml
100644 → 100755
CMakeLists.txt
100644 → 100755
Doxyfile
100644 → 100755
Jenkinsfile
100644 → 100755
LICENSE
100644 → 100755
README.md
100644 → 100755
cmake_uninstall.cmake.in
100644 → 100755
hueplusplus/CMakeLists.txt
100644 → 100755
hueplusplus/ExtendedColorHueStrategy.cpp
100644 → 100755
hueplusplus/ExtendedColorTemperatureStrategy.cpp
100644 → 100755
hueplusplus/Hue.cpp
100644 → 100755
| ... | ... | @@ -33,417 +33,362 @@ |
| 33 | 33 | |
| 34 | 34 | #include "include/UPnP.h" |
| 35 | 35 | |
| 36 | -HueFinder::HueFinder(std::shared_ptr<const IHttpHandler> handler) : http_handler(std::move(handler)) | |
| 37 | -{} | |
| 36 | +HueFinder::HueFinder(std::shared_ptr<const IHttpHandler> handler) | |
| 37 | + : http_handler(std::move(handler)) {} | |
| 38 | 38 | |
| 39 | -std::vector<HueFinder::HueIdentification> HueFinder::FindBridges() const | |
| 40 | -{ | |
| 41 | - UPnP uplug; | |
| 42 | - std::vector<std::pair<std::string, std::string>> foundDevices = uplug.getDevices(http_handler); | |
| 39 | +std::vector<HueFinder::HueIdentification> HueFinder::FindBridges() const { | |
| 40 | + UPnP uplug; | |
| 41 | + std::vector<std::pair<std::string, std::string>> foundDevices = | |
| 42 | + uplug.getDevices(http_handler); | |
| 43 | 43 | |
| 44 | - //Does not work | |
| 45 | - std::regex manufRegex("<manufacturer>Royal Philips Electronics</manufacturer>"); | |
| 46 | - std::regex manURLRegex("<manufacturerURL>http://www\\.philips\\.com</manufacturerURL>"); | |
| 47 | - std::regex modelRegex("<modelName>Philips hue bridge[^<]*</modelName>"); | |
| 48 | - std::regex serialRegex("<serialNumber>(\\w+)</serialNumber>"); | |
| 49 | - std::vector<HueIdentification> foundBridges; | |
| 50 | - for (const std::pair<std::string, std::string> &p : foundDevices) | |
| 51 | - { | |
| 52 | - size_t found = p.second.find("IpBridge"); | |
| 53 | - if (found != std::string::npos) | |
| 54 | - { | |
| 55 | - HueIdentification bridge; | |
| 56 | - size_t start = p.first.find("//") + 2; | |
| 57 | - size_t length = p.first.find(":", start) - start; | |
| 58 | - bridge.ip = p.first.substr(start, length); | |
| 59 | - std::string desc = http_handler->GETString("/description.xml", "application/xml", "", bridge.ip); | |
| 60 | - std::smatch matchResult; | |
| 61 | - if (std::regex_search(desc, manufRegex) && std::regex_search(desc, manURLRegex) && std::regex_search(desc, modelRegex) && std::regex_search(desc, matchResult, serialRegex)) | |
| 62 | - { | |
| 63 | - //The string matches | |
| 64 | - //Get 1st submatch (0 is whole match) | |
| 65 | - bridge.mac = matchResult[1].str(); | |
| 66 | - foundBridges.push_back(std::move(bridge)); | |
| 67 | - } | |
| 68 | - //break; | |
| 69 | - } | |
| 70 | - } | |
| 71 | - return foundBridges; | |
| 44 | + // Does not work | |
| 45 | + std::regex manufRegex( | |
| 46 | + "<manufacturer>Royal Philips Electronics</manufacturer>"); | |
| 47 | + std::regex manURLRegex( | |
| 48 | + "<manufacturerURL>http://www\\.philips\\.com</manufacturerURL>"); | |
| 49 | + std::regex modelRegex("<modelName>Philips hue bridge[^<]*</modelName>"); | |
| 50 | + std::regex serialRegex("<serialNumber>(\\w+)</serialNumber>"); | |
| 51 | + std::vector<HueIdentification> foundBridges; | |
| 52 | + for (const std::pair<std::string, std::string> &p : foundDevices) { | |
| 53 | + size_t found = p.second.find("IpBridge"); | |
| 54 | + if (found != std::string::npos) { | |
| 55 | + HueIdentification bridge; | |
| 56 | + size_t start = p.first.find("//") + 2; | |
| 57 | + size_t length = p.first.find(":", start) - start; | |
| 58 | + bridge.ip = p.first.substr(start, length); | |
| 59 | + std::string desc = http_handler->GETString( | |
| 60 | + "/description.xml", "application/xml", "", bridge.ip); | |
| 61 | + std::smatch matchResult; | |
| 62 | + if (std::regex_search(desc, manufRegex) && | |
| 63 | + std::regex_search(desc, manURLRegex) && | |
| 64 | + std::regex_search(desc, modelRegex) && | |
| 65 | + std::regex_search(desc, matchResult, serialRegex)) { | |
| 66 | + // The string matches | |
| 67 | + // Get 1st submatch (0 is whole match) | |
| 68 | + bridge.mac = matchResult[1].str(); | |
| 69 | + foundBridges.push_back(std::move(bridge)); | |
| 70 | + } | |
| 71 | + // break; | |
| 72 | + } | |
| 73 | + } | |
| 74 | + return foundBridges; | |
| 72 | 75 | } |
| 73 | 76 | |
| 77 | +Hue HueFinder::GetBridge(const HueIdentification &identification) { | |
| 78 | + std::string normalizedMac = NormalizeMac(identification.mac); | |
| 79 | + auto pos = usernames.find(normalizedMac); | |
| 80 | + if (pos != usernames.end()) { | |
| 81 | + return Hue(identification.ip, pos->second, http_handler); | |
| 82 | + } | |
| 83 | + Hue bridge(identification.ip, "", http_handler); | |
| 84 | + bridge.requestUsername(identification.ip); | |
| 85 | + if (bridge.getUsername().empty()) { | |
| 86 | + std::cerr << "Failed to request username for ip " << identification.ip | |
| 87 | + << std::endl; | |
| 88 | + throw std::runtime_error("Failed to request username!"); | |
| 89 | + } | |
| 90 | + AddUsername(normalizedMac, bridge.getUsername()); | |
| 74 | 91 | |
| 75 | -Hue HueFinder::GetBridge(const HueIdentification& identification) | |
| 76 | -{ | |
| 77 | - std::string normalizedMac = NormalizeMac(identification.mac); | |
| 78 | - auto pos = usernames.find(normalizedMac); | |
| 79 | - if (pos != usernames.end()) | |
| 80 | - { | |
| 81 | - return Hue(identification.ip, pos->second, http_handler); | |
| 82 | - } | |
| 83 | - Hue bridge(identification.ip, "", http_handler); | |
| 84 | - bridge.requestUsername(identification.ip); | |
| 85 | - if (bridge.getUsername().empty()) | |
| 86 | - { | |
| 87 | - std::cerr << "Failed to request username for ip " << identification.ip << std::endl; | |
| 88 | - throw std::runtime_error("Failed to request username!"); | |
| 89 | - } | |
| 90 | - AddUsername(normalizedMac, bridge.getUsername()); | |
| 91 | - | |
| 92 | - return bridge; | |
| 92 | + return bridge; | |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | -void HueFinder::AddUsername(const std::string& mac, const std::string& username) | |
| 96 | -{ | |
| 97 | - usernames[NormalizeMac(mac)] = username; | |
| 95 | +void HueFinder::AddUsername(const std::string &mac, | |
| 96 | + const std::string &username) { | |
| 97 | + usernames[NormalizeMac(mac)] = username; | |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | -const std::map<std::string, std::string>& HueFinder::GetAllUsernames() const | |
| 101 | -{ | |
| 102 | - return usernames; | |
| 100 | +const std::map<std::string, std::string> &HueFinder::GetAllUsernames() const { | |
| 101 | + return usernames; | |
| 103 | 102 | } |
| 104 | 103 | |
| 105 | -std::string HueFinder::NormalizeMac(std::string input) | |
| 106 | -{ | |
| 107 | - // Remove any non alphanumeric characters (e.g. ':' and whitespace) | |
| 108 | - input.erase(std::remove_if(input.begin(), input.end(), | |
| 109 | - [](char c) { return !std::isalnum(c, std::locale()); }), input.end()); | |
| 110 | - // Convert to lower case | |
| 111 | - std::transform(input.begin(), input.end(), input.begin(), | |
| 112 | - [](char c) { return std::tolower(c, std::locale()); }); | |
| 113 | - return input; | |
| 104 | +std::string HueFinder::NormalizeMac(std::string input) { | |
| 105 | + // Remove any non alphanumeric characters (e.g. ':' and whitespace) | |
| 106 | + input.erase( | |
| 107 | + std::remove_if(input.begin(), input.end(), | |
| 108 | + [](char c) { return !std::isalnum(c, std::locale()); }), | |
| 109 | + input.end()); | |
| 110 | + // Convert to lower case | |
| 111 | + std::transform(input.begin(), input.end(), input.begin(), | |
| 112 | + [](char c) { return std::tolower(c, std::locale()); }); | |
| 113 | + return input; | |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | +Hue::Hue(const std::string &ip, const std::string &username, | |
| 117 | + std::shared_ptr<const IHttpHandler> handler) | |
| 118 | + : ip(ip), username(username), http_handler(std::move(handler)), | |
| 119 | + commands(ip, username, http_handler), | |
| 120 | + simpleBrightnessStrategy(std::make_shared<SimpleBrightnessStrategy>()), | |
| 121 | + simpleColorHueStrategy(std::make_shared<SimpleColorHueStrategy>()), | |
| 122 | + extendedColorHueStrategy(std::make_shared<ExtendedColorHueStrategy>()), | |
| 123 | + simpleColorTemperatureStrategy( | |
| 124 | + std::make_shared<SimpleColorTemperatureStrategy>()), | |
| 125 | + extendedColorTemperatureStrategy( | |
| 126 | + std::make_shared<ExtendedColorTemperatureStrategy>()) {} | |
| 116 | 127 | |
| 117 | -Hue::Hue(const std::string& ip, const std::string& username, std::shared_ptr<const IHttpHandler> handler) | |
| 118 | - : ip(ip), | |
| 119 | - username(username), | |
| 120 | - http_handler(std::move(handler)), | |
| 121 | - commands(ip, username, http_handler), | |
| 122 | - simpleBrightnessStrategy(std::make_shared<SimpleBrightnessStrategy>()), | |
| 123 | - simpleColorHueStrategy(std::make_shared<SimpleColorHueStrategy>()), | |
| 124 | - extendedColorHueStrategy(std::make_shared<ExtendedColorHueStrategy>()), | |
| 125 | - simpleColorTemperatureStrategy(std::make_shared<SimpleColorTemperatureStrategy>()), | |
| 126 | - extendedColorTemperatureStrategy(std::make_shared<ExtendedColorTemperatureStrategy>()) | |
| 127 | -{} | |
| 128 | +std::string Hue::getBridgeIP() { return ip; } | |
| 128 | 129 | |
| 129 | -std::string Hue::getBridgeIP() | |
| 130 | -{ | |
| 131 | - return ip; | |
| 132 | -} | |
| 133 | - | |
| 134 | -std::string Hue::requestUsername(const std::string& ip) | |
| 135 | -{ | |
| 136 | - std::cout << "Please press the link Button! You've got 35 secs!\n"; // when the link button was presed we got 30 seconds to get our username for control | |
| 130 | +std::string Hue::requestUsername(const std::string &ip) { | |
| 131 | + std::cout | |
| 132 | + << "Please press the link Button! You've got 35 secs!\n"; // when the link | |
| 133 | + // button was | |
| 134 | + // pressed we | |
| 135 | + // got 30 | |
| 136 | + // seconds to | |
| 137 | + // get our | |
| 138 | + // username for | |
| 139 | + // control | |
| 137 | 140 | |
| 138 | - Json::Value request; | |
| 139 | - request["devicetype"] = "HuePlusPlus#User"; | |
| 141 | + Json::Value request; | |
| 142 | + request["devicetype"] = "HuePlusPlus#User"; | |
| 140 | 143 | |
| 141 | - Json::Value answer; | |
| 142 | - std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now(); | |
| 143 | - std::chrono::steady_clock::time_point lastCheck; | |
| 144 | - while (std::chrono::steady_clock::now() - start < std::chrono::seconds(35)) | |
| 145 | - { | |
| 146 | - if (std::chrono::steady_clock::now() - lastCheck > std::chrono::seconds(1)) | |
| 147 | - { | |
| 148 | - lastCheck = std::chrono::steady_clock::now(); | |
| 149 | - answer = http_handler->POSTJson("/api", request, ip); | |
| 144 | + Json::Value answer; | |
| 145 | + std::chrono::steady_clock::time_point start = | |
| 146 | + std::chrono::steady_clock::now(); | |
| 147 | + std::chrono::steady_clock::time_point lastCheck; | |
| 148 | + while (std::chrono::steady_clock::now() - start < std::chrono::seconds(35)) { | |
| 149 | + if (std::chrono::steady_clock::now() - lastCheck > | |
| 150 | + std::chrono::seconds(1)) { | |
| 151 | + lastCheck = std::chrono::steady_clock::now(); | |
| 152 | + answer = http_handler->POSTJson("/api", request, ip); | |
| 150 | 153 | |
| 151 | - if (answer[0]["success"] != Json::nullValue) | |
| 152 | - { | |
| 153 | - // [{"success":{"username": "<username>"}}] | |
| 154 | - username = answer[0]["success"]["username"].asString(); | |
| 155 | - this->ip = ip; | |
| 156 | - //Update commands with new username and ip | |
| 157 | - commands = HueCommandAPI(ip, username, http_handler); | |
| 158 | - std::cout << "Success! Link button was pressed!\n"; | |
| 159 | - std::cout << "Username is \"" << username << "\"\n"; | |
| 160 | - break; | |
| 161 | - } | |
| 162 | - if (answer[0]["error"] != Json::nullValue) | |
| 163 | - { | |
| 164 | - std::cout << "Link button not pressed!\n"; | |
| 165 | - } | |
| 166 | - } | |
| 167 | - } | |
| 168 | - return username; | |
| 154 | + if (answer[0]["success"] != Json::nullValue) { | |
| 155 | + // [{"success":{"username": "<username>"}}] | |
| 156 | + username = answer[0]["success"]["username"].asString(); | |
| 157 | + this->ip = ip; | |
| 158 | + // Update commands with new username and ip | |
| 159 | + commands = HueCommandAPI(ip, username, http_handler); | |
| 160 | + std::cout << "Success! Link button was pressed!\n"; | |
| 161 | + std::cout << "Username is \"" << username << "\"\n"; | |
| 162 | + break; | |
| 163 | + } | |
| 164 | + if (answer[0]["error"] != Json::nullValue) { | |
| 165 | + std::cout << "Link button not pressed!\n"; | |
| 166 | + } | |
| 167 | + } | |
| 168 | + } | |
| 169 | + return username; | |
| 169 | 170 | } |
| 170 | 171 | |
| 171 | -std::string Hue::getUsername() | |
| 172 | -{ | |
| 173 | - return username; | |
| 174 | -} | |
| 172 | +std::string Hue::getUsername() { return username; } | |
| 175 | 173 | |
| 176 | -void Hue::setIP(const std::string& ip) | |
| 177 | -{ | |
| 178 | - this->ip = ip; | |
| 179 | -} | |
| 174 | +void Hue::setIP(const std::string &ip) { this->ip = ip; } | |
| 180 | 175 | |
| 181 | -HueLight& Hue::getLight(int id) | |
| 182 | -{ | |
| 183 | - auto pos = lights.find(id); | |
| 184 | - if (pos != lights.end()) | |
| 185 | - { | |
| 186 | - pos->second.refreshState(); | |
| 187 | - return pos->second; | |
| 188 | - } | |
| 189 | - refreshState(); | |
| 190 | - if (!state["lights"].isMember(std::to_string(id))) | |
| 191 | - { | |
| 192 | - std::cerr << "Error in Hue getLight(): light with id " << id << " is not valid\n"; | |
| 193 | - throw(std::runtime_error("Error in Hue getLight(): light id is not valid")); | |
| 194 | - } | |
| 195 | - //std::cout << state["lights"][std::to_string(id)] << std::endl; | |
| 196 | - std::string type = state["lights"][std::to_string(id)]["modelid"].asString(); | |
| 197 | - //std::cout << type << std::endl; | |
| 198 | - if (type == "LCT001" || type == "LCT002" || type == "LCT003" || type == "LCT007" || type == "LLM001") | |
| 199 | - { | |
| 200 | - // HueExtendedColorLight Gamut B | |
| 201 | - HueLight light = HueLight(id, commands, simpleBrightnessStrategy, extendedColorTemperatureStrategy, extendedColorHueStrategy); | |
| 202 | - light.colorType = ColorType::GAMUT_B; | |
| 203 | - lights.emplace(id, light); | |
| 204 | - return lights.find(id)->second; | |
| 205 | - } | |
| 206 | - else if (type == "LCT010" || type == "LCT011" || type == "LCT014" || type == "LCT015" || type == "LCT016" || type == "LLC020" || type == "LST002") | |
| 207 | - { | |
| 208 | - // HueExtendedColorLight Gamut C | |
| 209 | - HueLight light = HueLight(id, commands, simpleBrightnessStrategy, extendedColorTemperatureStrategy, extendedColorHueStrategy); | |
| 210 | - light.colorType = ColorType::GAMUT_C; | |
| 211 | - lights.emplace(id, light); | |
| 212 | - return lights.find(id)->second; | |
| 213 | - } | |
| 214 | - else if (type == "LST001" || type == "LLC006" || type == "LLC007" || type == "LLC010" || type == "LLC011" || type == "LLC012" || type == "LLC013") | |
| 215 | - { | |
| 216 | - // HueColorLight Gamut A | |
| 217 | - HueLight light = HueLight(id, commands, simpleBrightnessStrategy, nullptr, simpleColorHueStrategy); | |
| 218 | - light.colorType = ColorType::GAMUT_A; | |
| 219 | - lights.emplace(id, light); | |
| 220 | - return lights.find(id)->second; | |
| 221 | - } | |
| 222 | - else if (type == "LWB004" || type == "LWB006" || type == "LWB007" || type == "LWB010" || type == "LWB014") | |
| 223 | - { | |
| 224 | - // HueDimmableLight No Color Type | |
| 225 | - HueLight light = HueLight(id, commands, simpleBrightnessStrategy, nullptr, nullptr); | |
| 226 | - light.colorType = ColorType::NONE; | |
| 227 | - lights.emplace(id, light); | |
| 228 | - return lights.find(id)->second; | |
| 229 | - } | |
| 230 | - else if (type == "LLM010" || type == "LLM011" || type == "LLM012" || type == "LTW001" || type == "LTW004" || type == "LTW013" || type == "LTW014") | |
| 231 | - { | |
| 232 | - // HueTemperatureLight | |
| 233 | - HueLight light = HueLight(id, commands, simpleBrightnessStrategy, simpleColorTemperatureStrategy, nullptr); | |
| 234 | - light.colorType = ColorType::TEMPERATURE; | |
| 235 | - lights.emplace(id, light); | |
| 236 | - return lights.find(id)->second; | |
| 237 | - } | |
| 238 | - std::cerr << "Could not determine HueLight type!\n"; | |
| 239 | - throw(std::runtime_error("Could not determine HueLight type!")); | |
| 176 | +HueLight &Hue::getLight(int id) { | |
| 177 | + auto pos = lights.find(id); | |
| 178 | + if (pos != lights.end()) { | |
| 179 | + pos->second.refreshState(); | |
| 180 | + return pos->second; | |
| 181 | + } | |
| 182 | + refreshState(); | |
| 183 | + if (!state["lights"].isMember(std::to_string(id))) { | |
| 184 | + std::cerr << "Error in Hue getLight(): light with id " << id | |
| 185 | + << " is not valid\n"; | |
| 186 | + throw(std::runtime_error("Error in Hue getLight(): light id is not valid")); | |
| 187 | + } | |
| 188 | + // std::cout << state["lights"][std::to_string(id)] << std::endl; | |
| 189 | + std::string type = state["lights"][std::to_string(id)]["modelid"].asString(); | |
| 190 | + // std::cout << type << std::endl; | |
| 191 | + if (type == "LCT001" || type == "LCT002" || type == "LCT003" || | |
| 192 | + type == "LCT007" || type == "LLM001") { | |
| 193 | + // HueExtendedColorLight Gamut B | |
| 194 | + HueLight light = | |
| 195 | + HueLight(id, commands, simpleBrightnessStrategy, | |
| 196 | + extendedColorTemperatureStrategy, extendedColorHueStrategy); | |
| 197 | + light.colorType = ColorType::GAMUT_B; | |
| 198 | + lights.emplace(id, light); | |
| 199 | + return lights.find(id)->second; | |
| 200 | + } else if (type == "LCT010" || type == "LCT011" || type == "LCT012" || | |
| 201 | + type == "LCT014" || type == "LCT015" || type == "LCT016" || | |
| 202 | + type == "LLC020" || type == "LST002") { | |
| 203 | + // HueExtendedColorLight Gamut C | |
| 204 | + HueLight light = | |
| 205 | + HueLight(id, commands, simpleBrightnessStrategy, | |
| 206 | + extendedColorTemperatureStrategy, extendedColorHueStrategy); | |
| 207 | + light.colorType = ColorType::GAMUT_C; | |
| 208 | + lights.emplace(id, light); | |
| 209 | + return lights.find(id)->second; | |
| 210 | + } else if (type == "LST001" || type == "LLC005" || type == "LLC006" || | |
| 211 | + type == "LLC007" || type == "LLC010" || type == "LLC011" || | |
| 212 | + type == "LLC012" || type == "LLC013" || type == "LLC014") { | |
| 213 | + // HueColorLight Gamut A | |
| 214 | + HueLight light = HueLight(id, commands, simpleBrightnessStrategy, nullptr, | |
| 215 | + simpleColorHueStrategy); | |
| 216 | + light.colorType = ColorType::GAMUT_A; | |
| 217 | + lights.emplace(id, light); | |
| 218 | + return lights.find(id)->second; | |
| 219 | + } else if (type == "LWB004" || type == "LWB006" || type == "LWB007" || | |
| 220 | + type == "LWB010" || type == "LWB014" || type == "LDF001" || | |
| 221 | + type == "LDF002" || type == "LDD001" || type == "LDD002" || | |
| 222 | + type == "MWM001") { | |
| 223 | + // HueDimmableLight No Color Type | |
| 224 | + HueLight light = | |
| 225 | + HueLight(id, commands, simpleBrightnessStrategy, nullptr, nullptr); | |
| 226 | + light.colorType = ColorType::NONE; | |
| 227 | + lights.emplace(id, light); | |
| 228 | + return lights.find(id)->second; | |
| 229 | + } else if (type == "LLM010" || type == "LLM011" || type == "LLM012" || | |
| 230 | + type == "LTW001" || type == "LTW004" || type == "LTW010" || | |
| 231 | + type == "LTW011" || type == "LTW012" || type == "LTW013" || | |
| 232 | + type == "LTW014" || type == "LTW015" || type == "LTP001" || | |
| 233 | + type == "LTP002" || type == "LTP003" || type == "LTP004" || | |
| 234 | + type == "LTP005" || type == "LTD003" || type == "LTF001" || | |
| 235 | + type == "LTF002" || type == "LTC001" || type == "LTC002" || | |
| 236 | + type == "LTC003" || type == "LTC004" || type == "LTC011" || | |
| 237 | + type == "LTC012" || type == "LTD001" || type == "LTD002" || | |
| 238 | + type == "LFF001" || type == "LTT001" || type == "LDT001") { | |
| 239 | + // HueTemperatureLight | |
| 240 | + HueLight light = HueLight(id, commands, simpleBrightnessStrategy, | |
| 241 | + simpleColorTemperatureStrategy, nullptr); | |
| 242 | + light.colorType = ColorType::TEMPERATURE; | |
| 243 | + lights.emplace(id, light); | |
| 244 | + return lights.find(id)->second; | |
| 245 | + } | |
| 246 | + std::cerr << "Could not determine HueLight type:" << type << "!\n"; | |
| 247 | + throw(std::runtime_error("Could not determine HueLight type!")); | |
| 240 | 248 | } |
| 241 | 249 | |
| 242 | -bool Hue::removeLight(int id) | |
| 243 | -{ | |
| 244 | - Json::Value result = commands.DELETERequest("/lights/" + std::to_string(id), Json::objectValue); | |
| 245 | - bool success = result.isArray() && !result[0].isNull() && result[0].isMember("success") && result[0]["success"] == "/lights/" + std::to_string(id) + " deleted"; | |
| 246 | - if (success && lights.count(id) != 0) | |
| 247 | - { | |
| 248 | - lights.erase(id); | |
| 249 | - } | |
| 250 | - return success; | |
| 250 | +bool Hue::removeLight(int id) { | |
| 251 | + Json::Value result = commands.DELETERequest("/lights/" + std::to_string(id), | |
| 252 | + Json::objectValue); | |
| 253 | + bool success = | |
| 254 | + result.isArray() && !result[0].isNull() && | |
| 255 | + result[0].isMember("success") && | |
| 256 | + result[0]["success"] == "/lights/" + std::to_string(id) + " deleted"; | |
| 257 | + if (success && lights.count(id) != 0) { | |
| 258 | + lights.erase(id); | |
| 259 | + } | |
| 260 | + return success; | |
| 251 | 261 | } |
| 252 | 262 | |
| 253 | -std::vector<std::reference_wrapper<HueLight>> Hue::getAllLights() | |
| 254 | -{ | |
| 255 | - refreshState(); | |
| 256 | - for (const auto& id : state["lights"].getMemberNames()) | |
| 257 | - { | |
| 258 | - getLight(std::stoi(id)); | |
| 259 | - } | |
| 260 | - std::vector<std::reference_wrapper<HueLight>> result; | |
| 261 | - for (auto& entry : lights) | |
| 262 | - { | |
| 263 | - result.emplace_back(entry.second); | |
| 264 | - } | |
| 265 | - return result; | |
| 263 | +std::vector<std::reference_wrapper<HueLight>> Hue::getAllLights() { | |
| 264 | + refreshState(); | |
| 265 | + for (const auto &id : state["lights"].getMemberNames()) { | |
| 266 | + getLight(std::stoi(id)); | |
| 267 | + } | |
| 268 | + std::vector<std::reference_wrapper<HueLight>> result; | |
| 269 | + for (auto &entry : lights) { | |
| 270 | + result.emplace_back(entry.second); | |
| 271 | + } | |
| 272 | + return result; | |
| 266 | 273 | } |
| 267 | 274 | |
| 268 | -bool Hue::lightExists(int id) | |
| 269 | -{ | |
| 270 | - refreshState(); | |
| 271 | - auto pos = lights.find(id); | |
| 272 | - if (pos != lights.end()) | |
| 273 | - { | |
| 274 | - return true; | |
| 275 | - } | |
| 276 | - if (state["lights"].isMember(std::to_string(id))) | |
| 277 | - { | |
| 278 | - return true; | |
| 279 | - } | |
| 280 | - return false; | |
| 275 | +bool Hue::lightExists(int id) { | |
| 276 | + refreshState(); | |
| 277 | + auto pos = lights.find(id); | |
| 278 | + if (pos != lights.end()) { | |
| 279 | + return true; | |
| 280 | + } | |
| 281 | + if (state["lights"].isMember(std::to_string(id))) { | |
| 282 | + return true; | |
| 283 | + } | |
| 284 | + return false; | |
| 281 | 285 | } |
| 282 | 286 | |
| 283 | -bool Hue::lightExists(int id) const | |
| 284 | -{ | |
| 285 | - auto pos = lights.find(id); | |
| 286 | - if (pos != lights.end()) | |
| 287 | - { | |
| 288 | - return true; | |
| 289 | - } | |
| 290 | - if (state["lights"].isMember(std::to_string(id))) | |
| 291 | - { | |
| 292 | - return true; | |
| 293 | - } | |
| 294 | - return false; | |
| 287 | +bool Hue::lightExists(int id) const { | |
| 288 | + auto pos = lights.find(id); | |
| 289 | + if (pos != lights.end()) { | |
| 290 | + return true; | |
| 291 | + } | |
| 292 | + if (state["lights"].isMember(std::to_string(id))) { | |
| 293 | + return true; | |
| 294 | + } | |
| 295 | + return false; | |
| 295 | 296 | } |
| 296 | 297 | |
| 297 | -std::string Hue::getPictureOfLight(int id) const | |
| 298 | -{ | |
| 299 | - std::string ret = ""; | |
| 300 | - auto pos = lights.find(id); | |
| 301 | - if (pos != lights.end()) | |
| 302 | - { | |
| 303 | - ret = getPictureOfModel(pos->second.getModelId()); | |
| 304 | - } | |
| 305 | - return ret; | |
| 298 | +std::string Hue::getPictureOfLight(int id) const { | |
| 299 | + std::string ret = ""; | |
| 300 | + auto pos = lights.find(id); | |
| 301 | + if (pos != lights.end()) { | |
| 302 | + ret = getPictureOfModel(pos->second.getModelId()); | |
| 303 | + } | |
| 304 | + return ret; | |
| 306 | 305 | } |
| 307 | 306 | |
| 308 | -std::string Hue::getPictureOfModel(const std::string& model_id) const | |
| 309 | -{ | |
| 310 | - std::string ret = ""; | |
| 311 | - if (model_id == "LCT001" || model_id == "LCT007" || model_id == "LCT010" || model_id == "LCT014" || | |
| 312 | - model_id == "LTW010" || model_id == "LTW001" || model_id == "LTW004" || model_id == "LTW015" || | |
| 313 | - model_id == "LWB004" || model_id == "LWB006") | |
| 314 | - { | |
| 315 | - ret.append("e27_waca"); | |
| 316 | - } | |
| 317 | - else if (model_id == "LWB010" || model_id == "LWB014") | |
| 318 | - { | |
| 319 | - ret.append("e27_white"); | |
| 320 | - } | |
| 321 | - else if (model_id == "LCT012" || model_id == "LTW012") | |
| 322 | - { | |
| 323 | - ret.append("e14"); | |
| 324 | - } | |
| 325 | - else if (model_id == "LCT002") | |
| 326 | - { | |
| 327 | - ret.append("br30"); | |
| 328 | - } | |
| 329 | - else if (model_id == "LCT011" || model_id == "LTW011") | |
| 330 | - { | |
| 331 | - ret.append("br30_slim"); | |
| 332 | - } | |
| 333 | - else if (model_id == "LCT003") | |
| 334 | - { | |
| 335 | - ret.append("gu10"); | |
| 336 | - } | |
| 337 | - else if (model_id == "LTW013") | |
| 338 | - { | |
| 339 | - ret.append("gu10_perfectfit"); | |
| 340 | - } | |
| 341 | - else if (model_id == "LST001" || model_id == "LST002") | |
| 342 | - { | |
| 343 | - ret.append("lightstrip"); | |
| 344 | - } | |
| 345 | - else if (model_id == "LLC006 " || model_id == "LLC010") | |
| 346 | - { | |
| 347 | - ret.append("iris"); | |
| 348 | - } | |
| 349 | - else if (model_id == "LLC005" || model_id == "LLC011" || model_id == "LLC012" || | |
| 350 | - model_id == "LLC007") | |
| 351 | - { | |
| 352 | - ret.append("bloom"); | |
| 353 | - } | |
| 354 | - else if (model_id == "LLC014") | |
| 355 | - { | |
| 356 | - ret.append("aura"); | |
| 357 | - } | |
| 358 | - else if (model_id == "LLC013") | |
| 359 | - { | |
| 360 | - ret.append("storylight"); | |
| 361 | - } | |
| 362 | - else if (model_id == "LLC020") | |
| 363 | - { | |
| 364 | - ret.append("go"); | |
| 365 | - } | |
| 366 | - else if (model_id == "HBL001" || model_id == "HBL002" || model_id == "HBL003") | |
| 367 | - { | |
| 368 | - ret.append("beyond_ceiling_pendant_table"); | |
| 369 | - } | |
| 370 | - else if (model_id == "HIL001 " || model_id == "HIL002") | |
| 371 | - { | |
| 372 | - ret.append("impulse"); | |
| 373 | - } | |
| 374 | - else if (model_id == "HEL001 " || model_id == "HEL002") | |
| 375 | - { | |
| 376 | - ret.append("entity"); | |
| 377 | - } | |
| 378 | - else if (model_id == "HML001" || model_id == "HML002" || model_id == "HML003" || | |
| 379 | - model_id == "HML004" || model_id == "HML005") | |
| 380 | - { | |
| 381 | - ret.append("phoenix_ceiling_pendant_table_wall"); | |
| 382 | - } | |
| 383 | - else if (model_id == "HML006") | |
| 384 | - { | |
| 385 | - ret.append("phoenix_down"); | |
| 386 | - } | |
| 387 | - else if (model_id == "LTP001" || model_id == "LTP002" || model_id == "LTP003" || | |
| 388 | - model_id == "LTP004" || model_id == "LTP005" || model_id == "LTD003") | |
| 389 | - { | |
| 390 | - ret.append("pendant"); | |
| 391 | - } | |
| 392 | - else if (model_id == "LDF002" || model_id == "LTF001" || model_id == "LTF002" || | |
| 393 | - model_id == "LTC001" || model_id == "LTC002" || model_id == "LTC003" || | |
| 394 | - model_id == "LTC004" || model_id == "LTD001" || model_id == "LTD002" || | |
| 395 | - model_id == "LDF001") | |
| 396 | - { | |
| 397 | - ret.append("ceiling"); | |
| 398 | - } | |
| 399 | - else if (model_id == "LDD002 " || model_id == "LFF001") | |
| 400 | - { | |
| 401 | - ret.append("floor"); | |
| 402 | - } | |
| 403 | - else if (model_id == "LDD001 " || model_id == "LTT001") | |
| 404 | - { | |
| 405 | - ret.append("table"); | |
| 406 | - } | |
| 407 | - else if (model_id == "LDT001 " || model_id == "MWM001") | |
| 408 | - { | |
| 409 | - ret.append("recessed"); | |
| 410 | - } | |
| 411 | - else if (model_id == "BSB001") | |
| 412 | - { | |
| 413 | - ret.append("bridge_v1"); | |
| 414 | - } | |
| 415 | - else if (model_id == "BSB002") | |
| 416 | - { | |
| 417 | - ret.append("bridge_v2"); | |
| 418 | - } | |
| 419 | - else if (model_id == "SWT001") | |
| 420 | - { | |
| 421 | - ret.append("tap"); | |
| 422 | - } | |
| 423 | - else if (model_id == "RWL021") | |
| 424 | - { | |
| 425 | - ret.append("hds"); | |
| 426 | - } | |
| 427 | - else if (model_id == "SML001") | |
| 428 | - { | |
| 429 | - ret.append("motion_sensor"); | |
| 430 | - } | |
| 431 | - return ret; | |
| 307 | +std::string Hue::getPictureOfModel(const std::string &model_id) const { | |
| 308 | + std::string ret = ""; | |
| 309 | + if (model_id == "LCT001" || model_id == "LCT007" || model_id == "LCT010" || | |
| 310 | + model_id == "LCT014" || model_id == "LTW010" || model_id == "LTW001" || | |
| 311 | + model_id == "LTW004" || model_id == "LTW015" || model_id == "LWB004" || | |
| 312 | + model_id == "LWB006") { | |
| 313 | + ret.append("e27_waca"); | |
| 314 | + } else if (model_id == "LWB010" || model_id == "LWB014") { | |
| 315 | + ret.append("e27_white"); | |
| 316 | + } else if (model_id == "LCT012" || model_id == "LTW012") { | |
| 317 | + ret.append("e14"); | |
| 318 | + } else if (model_id == "LCT002") { | |
| 319 | + ret.append("br30"); | |
| 320 | + } else if (model_id == "LCT011" || model_id == "LTW011") { | |
| 321 | + ret.append("br30_slim"); | |
| 322 | + } else if (model_id == "LCT003") { | |
| 323 | + ret.append("gu10"); | |
| 324 | + } else if (model_id == "LTW013") { | |
| 325 | + ret.append("gu10_perfectfit"); | |
| 326 | + } else if (model_id == "LST001" || model_id == "LST002") { | |
| 327 | + ret.append("lightstrip"); | |
| 328 | + } else if (model_id == "LLC006 " || model_id == "LLC010") { | |
| 329 | + ret.append("iris"); | |
| 330 | + } else if (model_id == "LLC005" || model_id == "LLC011" || | |
| 331 | + model_id == "LLC012" || model_id == "LLC007") { | |
| 332 | + ret.append("bloom"); | |
| 333 | + } else if (model_id == "LLC014") { | |
| 334 | + ret.append("aura"); | |
| 335 | + } else if (model_id == "LLC013") { | |
| 336 | + ret.append("storylight"); | |
| 337 | + } else if (model_id == "LLC020") { | |
| 338 | + ret.append("go"); | |
| 339 | + } else if (model_id == "HBL001" || model_id == "HBL002" || | |
| 340 | + model_id == "HBL003") { | |
| 341 | + ret.append("beyond_ceiling_pendant_table"); | |
| 342 | + } else if (model_id == "HIL001 " || model_id == "HIL002") { | |
| 343 | + ret.append("impulse"); | |
| 344 | + } else if (model_id == "HEL001 " || model_id == "HEL002") { | |
| 345 | + ret.append("entity"); | |
| 346 | + } else if (model_id == "HML001" || model_id == "HML002" || | |
| 347 | + model_id == "HML003" || model_id == "HML004" || | |
| 348 | + model_id == "HML005") { | |
| 349 | + ret.append("phoenix_ceiling_pendant_table_wall"); | |
| 350 | + } else if (model_id == "HML006") { | |
| 351 | + ret.append("phoenix_down"); | |
| 352 | + } else if (model_id == "LTP001" || model_id == "LTP002" || | |
| 353 | + model_id == "LTP003" || model_id == "LTP004" || | |
| 354 | + model_id == "LTP005" || model_id == "LTD003") { | |
| 355 | + ret.append("pendant"); | |
| 356 | + } else if (model_id == "LDF002" || model_id == "LTF001" || | |
| 357 | + model_id == "LTF002" || model_id == "LTC001" || | |
| 358 | + model_id == "LTC002" || model_id == "LTC003" || | |
| 359 | + model_id == "LTC004" || model_id == "LTD001" || | |
| 360 | + model_id == "LTD002" || model_id == "LDF001") { | |
| 361 | + ret.append("ceiling"); | |
| 362 | + } else if (model_id == "LDD002 " || model_id == "LFF001") { | |
| 363 | + ret.append("floor"); | |
| 364 | + } else if (model_id == "LDD001 " || model_id == "LTT001") { | |
| 365 | + ret.append("table"); | |
| 366 | + } else if (model_id == "LDT001 " || model_id == "MWM001") { | |
| 367 | + ret.append("recessed"); | |
| 368 | + } else if (model_id == "BSB001") { | |
| 369 | + ret.append("bridge_v1"); | |
| 370 | + } else if (model_id == "BSB002") { | |
| 371 | + ret.append("bridge_v2"); | |
| 372 | + } else if (model_id == "SWT001") { | |
| 373 | + ret.append("tap"); | |
| 374 | + } else if (model_id == "RWL021") { | |
| 375 | + ret.append("hds"); | |
| 376 | + } else if (model_id == "SML001") { | |
| 377 | + ret.append("motion_sensor"); | |
| 378 | + } | |
| 379 | + return ret; | |
| 432 | 380 | } |
| 433 | 381 | |
| 434 | -void Hue::refreshState() | |
| 435 | -{ | |
| 436 | - if (username.empty()) | |
| 437 | - { | |
| 438 | - return; | |
| 439 | - } | |
| 440 | - Json::Value answer = commands.GETRequest("", Json::objectValue); | |
| 441 | - if (answer.isObject() && answer.isMember("lights")) | |
| 442 | - { | |
| 443 | - state = answer; | |
| 444 | - } | |
| 445 | - else | |
| 446 | - { | |
| 447 | - std::cout << "Answer in Hue::refreshState of http_handler->GETJson(...) is not expected!\nAnswer:\n\t" << answer.toStyledString() << std::endl; | |
| 448 | - } | |
| 382 | +void Hue::refreshState() { | |
| 383 | + if (username.empty()) { | |
| 384 | + return; | |
| 385 | + } | |
| 386 | + Json::Value answer = commands.GETRequest("", Json::objectValue); | |
| 387 | + if (answer.isObject() && answer.isMember("lights")) { | |
| 388 | + state = answer; | |
| 389 | + } else { | |
| 390 | + std::cout << "Answer in Hue::refreshState of http_handler->GETJson(...) is " | |
| 391 | + "not expected!\nAnswer:\n\t" | |
| 392 | + << answer.toStyledString() << std::endl; | |
| 393 | + } | |
| 449 | 394 | } | ... | ... |
hueplusplus/HueCommandAPI.cpp
100644 → 100755
hueplusplus/HueLight.cpp
100644 → 100755
hueplusplus/LinHttpHandler.cpp
100644 → 100755
hueplusplus/SimpleBrightnessStrategy.cpp
100644 → 100755
hueplusplus/SimpleColorHueStrategy.cpp
100644 → 100755
hueplusplus/SimpleColorTemperatureStrategy.cpp
100644 → 100755
hueplusplus/UPnP.cpp
100644 → 100755
hueplusplus/WinHttpHandler.cpp
100644 → 100755
hueplusplus/hueplusplus-config.cmake.in
100644 → 100755
hueplusplus/include/BaseHttpHandler.h
100644 → 100755
hueplusplus/include/BrightnessStrategy.h
100644 → 100755
hueplusplus/include/ColorHueStrategy.h
100644 → 100755
hueplusplus/include/ColorTemperatureStrategy.h
100644 → 100755
hueplusplus/include/ExtendedColorHueStrategy.h
100644 → 100755
hueplusplus/include/ExtendedColorTemperatureStrategy.h
100644 → 100755
hueplusplus/include/Hue.h
100644 → 100755
hueplusplus/include/HueCommandAPI.h
100644 → 100755
hueplusplus/include/HueConfig.h
100644 → 100755
hueplusplus/include/HueLight.h
100644 → 100755
hueplusplus/include/IHttpHandler.h
100644 → 100755
hueplusplus/include/LinHttpHandler.h
100644 → 100755
hueplusplus/include/SimpleBrightnessStrategy.h
100644 → 100755
hueplusplus/include/SimpleColorHueStrategy.h
100644 → 100755
hueplusplus/include/SimpleColorTemperatureStrategy.h
100644 → 100755
hueplusplus/include/UPnP.h
100644 → 100755
hueplusplus/include/WinHttpHandler.h
100644 → 100755
hueplusplus/include/json/json-forwards.h
100644 → 100755
hueplusplus/include/json/json.h
100644 → 100755
hueplusplus/jsoncpp.cpp
100644 → 100755
hueplusplus/test/CMakeLists.txt
100644 → 100755
hueplusplus/test/CMakeLists.txt.in
100644 → 100755
hueplusplus/test/CodeCoverage.cmake
100644 → 100755
hueplusplus/test/mocks/mock_BaseHttpHandler.h
100644 → 100755
hueplusplus/test/mocks/mock_HttpHandler.h
100644 → 100755
hueplusplus/test/mocks/mock_HueLight.h
100644 → 100755
hueplusplus/test/test_BaseHttpHandler.cpp
100644 → 100755
hueplusplus/test/test_ExtendedColorHueStrategy.cpp
100644 → 100755
hueplusplus/test/test_ExtendedColorTemperatureStrategy.cpp
100644 → 100755
hueplusplus/test/test_Hue.cpp
100644 → 100755
hueplusplus/test/test_HueCommandAPI.cpp
100644 → 100755
hueplusplus/test/test_HueLight.cpp
100644 → 100755
hueplusplus/test/test_Main.cpp
100644 → 100755
hueplusplus/test/test_SimpleBrightnessStrategy.cpp
100644 → 100755
hueplusplus/test/test_SimpleColorHueStrategy.cpp
100644 → 100755
hueplusplus/test/test_SimpleColorTemperatureStrategy.cpp
100644 → 100755
hueplusplus/test/test_UPnP.cpp
100644 → 100755
hueplusplus/test/testhelper.h
100644 → 100755