Commit 85df039c0f03e23a02249404253d5c12cdaaa220
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 | 22 | #include <algorithm> |
| 23 | 23 | #include <cctype> |
| 24 | 24 | #include <chrono> |
| 25 | +#include <cstring> | |
| 25 | 26 | #include <iostream> |
| 26 | 27 | #include <locale> |
| 27 | 28 | #include <stdexcept> |
| ... | ... | @@ -104,19 +105,16 @@ std::string HueFinder::NormalizeMac(std::string input) { |
| 104 | 105 | |
| 105 | 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 | 108 | const char* model = "<modelName>Philips hue bridge"; |
| 110 | 109 | const char* serialBegin = "<serialNumber>"; |
| 111 | 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 | 112 | std::size_t begin = description.find(serialBegin); |
| 115 | 113 | std::size_t end = description.find(serialEnd, begin); |
| 116 | 114 | if (begin != std::string::npos && end != std::string::npos) { |
| 117 | 115 | begin += std::strlen(serialBegin); |
| 118 | 116 | if (begin < description.size()) { |
| 119 | - std::string result = description.substr(begin, end); | |
| 117 | + std::string result = description.substr(begin, end - begin); | |
| 120 | 118 | return result; |
| 121 | 119 | } |
| 122 | 120 | } | ... | ... |