Commit 85df039c0f03e23a02249404253d5c12cdaaa220

Authored by Jojo-1000
Committed by Jan
1 parent 648a545b

Fix ParseDescription, now also works for different manufacturers.

Showing 1 changed file with 3 additions and 5 deletions
hueplusplus/Hue.cpp
@@ -22,6 +22,7 @@ @@ -22,6 +22,7 @@
22 #include <algorithm> 22 #include <algorithm>
23 #include <cctype> 23 #include <cctype>
24 #include <chrono> 24 #include <chrono>
  25 +#include <cstring>
25 #include <iostream> 26 #include <iostream>
26 #include <locale> 27 #include <locale>
27 #include <stdexcept> 28 #include <stdexcept>
@@ -104,19 +105,16 @@ std::string HueFinder::NormalizeMac(std::string input) { @@ -104,19 +105,16 @@ std::string HueFinder::NormalizeMac(std::string input) {
104 105
105 std::string HueFinder::ParseDescription(const std::string & description) 106 std::string HueFinder::ParseDescription(const std::string & description)
106 { 107 {
107 - const char* manufacturer = "<manufacturer>Royal Philips Electronics</manufacturer>";  
108 - const char* manURL = "<manufacturerURL>http://www.philips.com</manufacturerURL>";  
109 const char* model = "<modelName>Philips hue bridge"; 108 const char* model = "<modelName>Philips hue bridge";
110 const char* serialBegin = "<serialNumber>"; 109 const char* serialBegin = "<serialNumber>";
111 const char* serialEnd = "</serialNumber>"; 110 const char* serialEnd = "</serialNumber>";
112 - if (description.find(manufacturer) != std::string::npos && description.find(manURL) != std::string::npos  
113 - && description.find(model) != std::string::npos) { 111 + if (description.find(model) != std::string::npos) {
114 std::size_t begin = description.find(serialBegin); 112 std::size_t begin = description.find(serialBegin);
115 std::size_t end = description.find(serialEnd, begin); 113 std::size_t end = description.find(serialEnd, begin);
116 if (begin != std::string::npos && end != std::string::npos) { 114 if (begin != std::string::npos && end != std::string::npos) {
117 begin += std::strlen(serialBegin); 115 begin += std::strlen(serialBegin);
118 if (begin < description.size()) { 116 if (begin < description.size()) {
119 - std::string result = description.substr(begin, end); 117 + std::string result = description.substr(begin, end - begin);
120 return result; 118 return result;
121 } 119 }
122 } 120 }