Commit 86d60f05435eb42df13b51c96de3b712e9363793

Authored by Sieren
Committed by Moritz Wirger
1 parent 704f96a7

Support Ports other than 80

Occasionally Hue-protocol emulating systems like DeCONZ,
Phoscon / ConBee can run on ports other than 80.
Especially if running on a Raspberry Pi server,
a user might run this on a different port than 80.
hueplusplus/Hue.cpp
... ... @@ -52,8 +52,11 @@ std::vector<HueFinder::HueIdentification> HueFinder::FindBridges() const {
52 52 size_t start = p.first.find("//") + 2;
53 53 size_t length = p.first.find(":", start) - start;
54 54 bridge.ip = p.first.substr(start, length);
  55 + auto portLength = p.first.find("/", start + length) - (start + length + 1);
  56 + auto port = p.first.substr(start + length + 1, portLength);
  57 + bridge.port = std::stoi(port);
55 58 std::string desc = http_handler->GETString(
56   - "/description.xml", "application/xml", "", bridge.ip);
  59 + "/description.xml", "application/xml", "", bridge.ip, bridge.port);
57 60 std::string mac = ParseDescription(desc);
58 61 if (!mac.empty()) {
59 62 bridge.mac = NormalizeMac(mac);
... ... @@ -68,9 +71,10 @@ Hue HueFinder::GetBridge(const HueIdentification &identification) {
68 71 std::string normalizedMac = NormalizeMac(identification.mac);
69 72 auto pos = usernames.find(normalizedMac);
70 73 if (pos != usernames.end()) {
71   - return Hue(identification.ip, pos->second, http_handler);
  74 + return Hue(identification.ip, identification.port,
  75 + pos->second, http_handler);
72 76 }
73   - Hue bridge(identification.ip, "", http_handler);
  77 + Hue bridge(identification.ip, identification.port, "", http_handler);
74 78 bridge.requestUsername(identification.ip);
75 79 if (bridge.getUsername().empty()) {
76 80 std::cerr << "Failed to request username for ip " << identification.ip
... ... @@ -122,9 +126,9 @@ std::string HueFinder::ParseDescription(const std::string &amp; description)
122 126 return std::string();
123 127 }
124 128  
125   -Hue::Hue(const std::string &ip, const std::string &username,
  129 +Hue::Hue(const std::string &ip, const int port, const std::string &username,
126 130 std::shared_ptr<const IHttpHandler> handler)
127   - : ip(ip), username(username),
  131 + : ip(ip), port(port), username(username),
128 132 simpleBrightnessStrategy(std::make_shared<SimpleBrightnessStrategy>()),
129 133 simpleColorHueStrategy(std::make_shared<SimpleColorHueStrategy>()),
130 134 extendedColorHueStrategy(std::make_shared<ExtendedColorHueStrategy>()),
... ... @@ -132,10 +136,13 @@ Hue::Hue(const std::string &amp;ip, const std::string &amp;username,
132 136 std::make_shared<SimpleColorTemperatureStrategy>()),
133 137 extendedColorTemperatureStrategy(
134 138 std::make_shared<ExtendedColorTemperatureStrategy>()),
135   - http_handler(std::move(handler)), commands(ip, username, http_handler) {}
  139 + http_handler(std::move(handler)), commands(ip, port, username,
  140 + http_handler) {}
136 141  
137 142 std::string Hue::getBridgeIP() { return ip; }
138 143  
  144 +int Hue::getBridgePort() { return port; }
  145 +
139 146 std::string Hue::requestUsername(const std::string &ip) {
140 147 std::cout
141 148 << "Please press the link Button! You've got 35 secs!\n"; // when the link
... ... @@ -158,14 +165,14 @@ std::string Hue::requestUsername(const std::string &amp;ip) {
158 165 if (std::chrono::steady_clock::now() - lastCheck >
159 166 std::chrono::seconds(1)) {
160 167 lastCheck = std::chrono::steady_clock::now();
161   - answer = http_handler->POSTJson("/api", request, ip);
  168 + answer = http_handler->POSTJson("/api", request, ip, port);
162 169  
163 170 if (answer[0]["success"] != Json::nullValue) {
164 171 // [{"success":{"username": "<username>"}}]
165 172 username = answer[0]["success"]["username"].asString();
166 173 this->ip = ip;
167 174 // Update commands with new username and ip
168   - commands = HueCommandAPI(ip, username, http_handler);
  175 + commands = HueCommandAPI(ip, port, username, http_handler);
169 176 std::cout << "Success! Link button was pressed!\n";
170 177 std::cout << "Username is \"" << username << "\"\n";
171 178 break;
... ... @@ -182,6 +189,8 @@ std::string Hue::getUsername() { return username; }
182 189  
183 190 void Hue::setIP(const std::string &ip) { this->ip = ip; }
184 191  
  192 +void Hue::setPort(const int port) { this->port = port; }
  193 +
185 194 HueLight &Hue::getLight(int id) {
186 195 auto pos = lights.find(id);
187 196 if (pos != lights.end()) {
... ...
hueplusplus/HueCommandAPI.cpp
... ... @@ -23,9 +23,10 @@
23 23  
24 24 constexpr std::chrono::steady_clock::duration HueCommandAPI::minDelay;
25 25  
26   -HueCommandAPI::HueCommandAPI(const std::string &ip, const std::string &username,
  26 +HueCommandAPI::HueCommandAPI(const std::string &ip, const int port,
  27 + const std::string &username,
27 28 std::shared_ptr<const IHttpHandler> httpHandler)
28   - : ip(ip), username(username), httpHandler(std::move(httpHandler)),
  29 + : ip(ip), port(port), username(username), httpHandler(std::move(httpHandler)),
29 30 timeout(new TimeoutData{std::chrono::steady_clock::now()}) {}
30 31  
31 32 Json::Value HueCommandAPI::PUTRequest(const std::string &path,
... ... @@ -40,7 +41,7 @@ Json::Value HueCommandAPI::PUTRequest(const std::string &amp;path,
40 41 "/api/" + username + (path.empty() || path.front() == '/' ? "" : "/") +
41 42 path;
42 43 try {
43   - Json::Value v = httpHandler->PUTJson(combinedPath, request, ip);
  44 + Json::Value v = httpHandler->PUTJson(combinedPath, request, ip, port);
44 45 timeout->timeout = now + minDelay;
45 46 return v;
46 47 } catch (const std::system_error &e) {
... ... @@ -69,7 +70,7 @@ Json::Value HueCommandAPI::GETRequest(const std::string &amp;path,
69 70 "/api/" + username + (path.empty() || path.front() == '/' ? "" : "/") +
70 71 path;
71 72 try {
72   - Json::Value v = httpHandler->GETJson(combinedPath, request, ip);
  73 + Json::Value v = httpHandler->GETJson(combinedPath, request, ip, port);
73 74 timeout->timeout = now + minDelay;
74 75 return v;
75 76 } catch (const std::system_error &e) {
... ... @@ -77,7 +78,7 @@ Json::Value HueCommandAPI::GETRequest(const std::string &amp;path,
77 78 e.code() == std::errc::timed_out) {
78 79 // Happens when hue is too busy, wait and try again (once)
79 80 std::this_thread::sleep_for(minDelay);
80   - Json::Value v = httpHandler->GETJson(combinedPath, request, ip);
  81 + Json::Value v = httpHandler->GETJson(combinedPath, request, ip, port);
81 82 timeout->timeout = std::chrono::steady_clock::now() + minDelay;
82 83 return v;
83 84 }
... ... @@ -98,7 +99,7 @@ Json::Value HueCommandAPI::DELETERequest(const std::string &amp;path,
98 99 "/api/" + username + (path.empty() || path.front() == '/' ? "" : "/") +
99 100 path;
100 101 try {
101   - Json::Value v = httpHandler->DELETEJson(combinedPath, request, ip);
  102 + Json::Value v = httpHandler->DELETEJson(combinedPath, request, ip, port);
102 103 timeout->timeout = now + minDelay;
103 104 return v;
104 105 } catch (const std::system_error &e) {
... ... @@ -106,7 +107,7 @@ Json::Value HueCommandAPI::DELETERequest(const std::string &amp;path,
106 107 e.code() == std::errc::timed_out) {
107 108 // Happens when hue is too busy, wait and try again (once)
108 109 std::this_thread::sleep_for(minDelay);
109   - Json::Value v = httpHandler->DELETEJson(combinedPath, request, ip);
  110 + Json::Value v = httpHandler->DELETEJson(combinedPath, request, ip, port);
110 111 timeout->timeout = std::chrono::steady_clock::now() + minDelay;
111 112 return v;
112 113 }
... ...
hueplusplus/include/Hue.h
... ... @@ -45,6 +45,7 @@ class HueFinder {
45 45 public:
46 46 struct HueIdentification {
47 47 std::string ip;
  48 + int port = 80;
48 49 std::string mac;
49 50 };
50 51  
... ... @@ -107,18 +108,23 @@ public:
107 108 //! \brief Constructor of Hue class
108 109 //!
109 110 //! \param ip String that specifies the ip address of the Hue bridge in dotted
110   - //! decimal notation like "192.168.2.1" \param username String that specifies
111   - //! the username that is used to control the bridge. This needs to be acquired
112   - //! in \ref requestUsername \param handler HttpHandler of type \ref
113   - //! IHttpHandler for communication with the bridge
114   - Hue(const std::string &ip, const std::string &username,
115   - std::shared_ptr<const IHttpHandler> handler);
  111 + //! decimal notation like "192.168.2.1" \param port Port of the hue bridge
  112 + //! \param username String that specifies the username that is used to control
  113 + //! the bridge. This needs to be acquired in \ref requestUsername \param handler
  114 + //! HttpHandler of type \ref IHttpHandler for communication with the bridge
  115 + Hue(const std::string &ip, const int port, const std::string &username,
  116 + std::shared_ptr<const IHttpHandler> handler);
116 117  
117 118 //! \brief Function to get the ip address of the hue bridge
118 119 //!
119 120 //! \return string containing ip
120 121 std::string getBridgeIP();
121 122  
  123 + //! \brief Function to get the port of the hue bridge
  124 + //!
  125 + //! \return integer containing port
  126 + int getBridgePort();
  127 +
122 128 //! \brief Function that sends a username request to the Hue bridge.
123 129 //!
124 130 //! It does that for about 30 seconds and you have 5 seconds to prepare
... ... @@ -141,6 +147,12 @@ public:
141 147 //! "192.168.2.1"
142 148 void setIP(const std::string &ip);
143 149  
  150 + //! \brief Function to set the port of this class representing a bridge
  151 + //!
  152 + //! \param port Integer that specifies the port of an address like
  153 + //! "192.168.2.1:8080"
  154 + void setPort(const int port);
  155 +
144 156 //! \brief Function that returns a \ref Hue::HueLight of specified id
145 157 //!
146 158 //! \param id Integer that specifies the ID of a Hue light
... ... @@ -209,7 +221,7 @@ public:
209 221 //! \param handler a HttpHandler of type \ref IHttpHandler
210 222 void setHttpHandler(std::shared_ptr<const IHttpHandler> handler) {
211 223 http_handler = std::move(handler);
212   - commands = HueCommandAPI(ip, username, http_handler);
  224 + commands = HueCommandAPI(ip, port, username, http_handler);
213 225 };
214 226  
215 227 private:
... ... @@ -219,6 +231,7 @@ private:
219 231 private:
220 232 std::string ip; //!< IP-Address of the hue bridge in dotted decimal notation
221 233 //!< like "192.168.2.1"
  234 + int port;
222 235 std::string username; //!< Username that is ussed to access the hue bridge
223 236 Json::Value state; //!< The state of the hue bridge as it is returned from it
224 237 std::map<uint8_t, HueLight>
... ...
hueplusplus/include/HueCommandAPI.h
... ... @@ -33,10 +33,11 @@ public:
33 33 //! \brief Construct from ip, username and HttpHandler
34 34 //!
35 35 //! \param ip String that specifies the ip address of the Hue bridge in dotted
36   - //! decimal notation like "192.168.2.1" \param username String that specifies
37   - //! the username that is used to control the bridge \param handler HttpHandler
38   - //! of type \ref IHttpHandler for communication with the bridge
39   - HueCommandAPI(const std::string &ip, const std::string &username,
  36 + //! decimal notation like "192.168.2.1" \param port of the hue bridge
  37 + //! \param username String that specifies the username that is used to control
  38 + //! the bridge \param handler HttpHandler of type \ref IHttpHandler for
  39 + //! communication with the bridge
  40 + HueCommandAPI(const std::string &ip, const int port, const std::string &username,
40 41 std::shared_ptr<const IHttpHandler> httpHandler);
41 42  
42 43 //! \brief Copy construct from other HueCommandAPI
... ... @@ -100,6 +101,7 @@ private:
100 101 static constexpr std::chrono::steady_clock::duration minDelay =
101 102 std::chrono::milliseconds(100);
102 103 std::string ip;
  104 + int port;
103 105 std::string username;
104 106 std::shared_ptr<const IHttpHandler> httpHandler;
105 107 std::shared_ptr<TimeoutData> timeout;
... ...
hueplusplus/test/mocks/mock_HueLight.h
... ... @@ -33,7 +33,9 @@
33 33 class MockHueLight : public HueLight
34 34 {
35 35 public:
36   - MockHueLight(std::shared_ptr<const IHttpHandler> handler) : HueLight(1, HueCommandAPI(getBridgeIp(), getBridgeUsername(), handler)) {};
  36 + MockHueLight(std::shared_ptr<const IHttpHandler> handler) : HueLight(1,
  37 + HueCommandAPI(getBridgeIp(), getBridgePort(), getBridgeUsername(),
  38 + handler)) {};
37 39  
38 40 Json::Value& getState() { return state; };
39 41  
... ...
hueplusplus/test/test_Hue.cpp
... ... @@ -45,16 +45,19 @@ TEST_F(HueFinderTest, FindBridges) {
45 45  
46 46 HueFinder::HueIdentification bridge_to_comp;
47 47 bridge_to_comp.ip = getBridgeIp();
  48 + bridge_to_comp.port = getBridgePort();
48 49 bridge_to_comp.mac = getBridgeMac();
49 50  
50 51 EXPECT_EQ(bridges.size(), 1) << "HueFinder found more than one Bridge";
51 52 EXPECT_EQ(bridges[0].ip, bridge_to_comp.ip)
52 53 << "HueIdentification ip does not match";
  54 + EXPECT_EQ(bridges[0].port, bridge_to_comp.port)
  55 + << "HueIdentification port does not match";
53 56 EXPECT_EQ(bridges[0].mac, bridge_to_comp.mac)
54 57 << "HueIdentification mac does not match";
55 58  
56 59 // Test invalid description
57   - EXPECT_CALL(*handler, GETString("/description.xml", "application/xml", "", getBridgeIp(), 80))
  60 + EXPECT_CALL(*handler, GETString("/description.xml", "application/xml", "", getBridgeIp(), getBridgePort()))
58 61 .Times(1)
59 62 .WillOnce(::testing::Return("invalid stuff"));
60 63 bridges = finder.FindBridges();
... ... @@ -100,6 +103,8 @@ TEST_F(HueFinderTest, GetBridge) {
100 103  
101 104 EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp())
102 105 << "Bridge IP not matching";
  106 + EXPECT_EQ(test_bridge.getBridgePort(), getBridgePort())
  107 + << "Bridge Port not matching";
103 108 EXPECT_EQ(test_bridge.getUsername(), getBridgeUsername())
104 109 << "Bridge username not matching";
105 110  
... ... @@ -126,6 +131,8 @@ TEST_F(HueFinderTest, AddUsername) {
126 131  
127 132 EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp())
128 133 << "Bridge IP not matching";
  134 + EXPECT_EQ(test_bridge.getBridgePort(), getBridgePort())
  135 + << "Bridge Port not matching";
129 136 EXPECT_EQ(test_bridge.getUsername(), getBridgeUsername())
130 137 << "Bridge username not matching";
131 138 }
... ... @@ -144,10 +151,12 @@ TEST_F(HueFinderTest, GetAllUsernames) {
144 151 TEST(Hue, Constructor) {
145 152 std::shared_ptr<MockHttpHandler> handler =
146 153 std::make_shared<MockHttpHandler>();
147   - Hue test_bridge(getBridgeIp(), getBridgeUsername(), handler);
  154 + Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
148 155  
149 156 EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp())
150 157 << "Bridge IP not matching";
  158 + EXPECT_EQ(test_bridge.getBridgePort(), getBridgePort())
  159 + << "Bridge Port not matching";
151 160 EXPECT_EQ(test_bridge.getUsername(), getBridgeUsername())
152 161 << "Bridge username not matching";
153 162 }
... ... @@ -167,11 +176,11 @@ TEST(Hue, requestUsername) {
167 176 user_ret_uns[0]["error"]["address"] = "";
168 177 user_ret_uns[0]["error"]["description"] = "link button not pressed";
169 178  
170   - EXPECT_CALL(*handler, POSTJson("/api", request, getBridgeIp(), 80))
  179 + EXPECT_CALL(*handler, POSTJson("/api", request, getBridgeIp(), getBridgePort()))
171 180 .Times(AtLeast(1))
172 181 .WillRepeatedly(Return(user_ret_uns));
173 182  
174   - Hue test_bridge(getBridgeIp(), "", handler);
  183 + Hue test_bridge(getBridgeIp(), getBridgePort(), "", handler);
175 184  
176 185 test_bridge.requestUsername(test_bridge.getBridgeIP());
177 186 EXPECT_EQ(test_bridge.getUsername(), "") << "Bridge username not matching";
... ... @@ -185,7 +194,7 @@ TEST(Hue, requestUsername) {
185 194 .Times(1)
186 195 .WillRepeatedly(Return(user_ret_suc));
187 196  
188   - test_bridge = Hue(getBridgeIp(), "", handler);
  197 + test_bridge = Hue(getBridgeIp(), getBridgePort(), "", handler);
189 198  
190 199 test_bridge.requestUsername(test_bridge.getBridgeIP());
191 200  
... ... @@ -209,7 +218,7 @@ TEST(Hue, requestUsername) {
209 218 TEST(Hue, setIP) {
210 219 std::shared_ptr<MockHttpHandler> handler =
211 220 std::make_shared<MockHttpHandler>();
212   - Hue test_bridge(getBridgeIp(), "", handler);
  221 + Hue test_bridge = Hue(getBridgeIp(), getBridgePort(), "", handler);
213 222 EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp())
214 223 << "Bridge IP not matching after initialization";
215 224 test_bridge.setIP("192.168.2.112");
... ... @@ -217,6 +226,17 @@ TEST(Hue, setIP) {
217 226 << "Bridge IP not matching after setting it";
218 227 }
219 228  
  229 +TEST(Hue, setPort) {
  230 + std::shared_ptr<MockHttpHandler> handler =
  231 + std::make_shared<MockHttpHandler>();
  232 + Hue test_bridge = Hue(getBridgeIp(), getBridgePort(), "", handler);
  233 + EXPECT_EQ(test_bridge.getBridgePort(), getBridgePort())
  234 + << "Bridge Port not matching after initialization";
  235 + test_bridge.setPort(81);
  236 + EXPECT_EQ(test_bridge.getBridgePort(), 81)
  237 + << "Bridge Port not matching after setting it";
  238 +}
  239 +
220 240 TEST(Hue, getLight) {
221 241 using namespace ::testing;
222 242 std::shared_ptr<MockHttpHandler> handler =
... ... @@ -226,7 +246,7 @@ TEST(Hue, getLight) {
226 246 Json::Value(Json::objectValue), getBridgeIp(), 80))
227 247 .Times(1);
228 248  
229   - Hue test_bridge(getBridgeIp(), getBridgeUsername(), handler);
  249 + Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
230 250  
231 251 // Test exception
232 252 ASSERT_THROW(test_bridge.getLight(1), std::runtime_error);
... ... @@ -286,7 +306,7 @@ TEST(Hue, getLight) {
286 306 Json::Value(Json::objectValue), getBridgeIp(), 80))
287 307 .Times(AtLeast(1))
288 308 .WillRepeatedly(Return(hue_bridge_state["lights"]["1"]));
289   - test_bridge = Hue(getBridgeIp(), getBridgeUsername(), handler);
  309 + test_bridge = Hue(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
290 310  
291 311 // Test when correct data is sent
292 312 test_light_1 = test_bridge.getLight(1);
... ... @@ -305,7 +325,7 @@ TEST(Hue, getLight) {
305 325 Json::Value(Json::objectValue), getBridgeIp(), 80))
306 326 .Times(AtLeast(1))
307 327 .WillRepeatedly(Return(hue_bridge_state["lights"]["1"]));
308   - test_bridge = Hue(getBridgeIp(), getBridgeUsername(), handler);
  328 + test_bridge = Hue(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
309 329  
310 330 // Test when correct data is sent
311 331 test_light_1 = test_bridge.getLight(1);
... ... @@ -324,7 +344,7 @@ TEST(Hue, getLight) {
324 344 Json::Value(Json::objectValue), getBridgeIp(), 80))
325 345 .Times(AtLeast(1))
326 346 .WillRepeatedly(Return(hue_bridge_state["lights"]["1"]));
327   - test_bridge = Hue(getBridgeIp(), getBridgeUsername(), handler);
  347 + test_bridge = Hue(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
328 348  
329 349 // Test when correct data is sent
330 350 test_light_1 = test_bridge.getLight(1);
... ... @@ -343,7 +363,7 @@ TEST(Hue, getLight) {
343 363 Json::Value(Json::objectValue), getBridgeIp(), 80))
344 364 .Times(AtLeast(1))
345 365 .WillRepeatedly(Return(hue_bridge_state["lights"]["1"]));
346   - test_bridge = Hue(getBridgeIp(), getBridgeUsername(), handler);
  366 + test_bridge = Hue(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
347 367  
348 368 // Test when correct data is sent
349 369 test_light_1 = test_bridge.getLight(1);
... ... @@ -356,7 +376,7 @@ TEST(Hue, getLight) {
356 376 Json::Value(Json::objectValue), getBridgeIp(), 80))
357 377 .Times(1)
358 378 .WillOnce(Return(hue_bridge_state));
359   - test_bridge = Hue(getBridgeIp(), getBridgeUsername(), handler);
  379 + test_bridge = Hue(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
360 380  
361 381 ASSERT_THROW(test_bridge.getLight(1), std::runtime_error);
362 382 }
... ... @@ -390,7 +410,7 @@ TEST(Hue, removeLight) {
390 410 .Times(1)
391 411 .WillOnce(Return(hue_bridge_state));
392 412  
393   - Hue test_bridge(getBridgeIp(), getBridgeUsername(), handler);
  413 + Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
394 414  
395 415 EXPECT_CALL(*handler,
396 416 GETJson("/api/" + getBridgeUsername() + "/lights/1",
... ... @@ -452,7 +472,7 @@ TEST(Hue, getAllLights) {
452 472 .Times(2)
453 473 .WillRepeatedly(Return(hue_bridge_state["lights"]["1"]));
454 474  
455   - Hue test_bridge(getBridgeIp(), getBridgeUsername(), handler);
  475 + Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
456 476  
457 477 std::vector<std::reference_wrapper<HueLight>> test_lights =
458 478 test_bridge.getAllLights();
... ... @@ -495,7 +515,7 @@ TEST(Hue, lightExists) {
495 515 .Times(AtLeast(1))
496 516 .WillRepeatedly(Return(hue_bridge_state["lights"]["1"]));
497 517  
498   - Hue test_bridge(getBridgeIp(), getBridgeUsername(), handler);
  518 + Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
499 519  
500 520 EXPECT_EQ(true, test_bridge.lightExists(1));
501 521 EXPECT_EQ(false, test_bridge.lightExists(2));
... ... @@ -545,7 +565,7 @@ TEST(Hue, getPictureOfLight) {
545 565 .Times(AtLeast(1))
546 566 .WillRepeatedly(Return(hue_bridge_state["lights"]["1"]));
547 567  
548   - Hue test_bridge(getBridgeIp(), getBridgeUsername(), handler);
  568 + Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
549 569  
550 570 test_bridge.getLight(1);
551 571  
... ... @@ -557,7 +577,7 @@ TEST(Hue, getPictureOfLight) {
557 577 TEST(Hue, refreshState) {
558 578 std::shared_ptr<MockHttpHandler> handler =
559 579 std::make_shared<MockHttpHandler>();
560   - Hue test_bridge(getBridgeIp(), "",
  580 + Hue test_bridge(getBridgeIp(), getBridgePort(), "",
561 581 handler); // NULL as username leads to segfault
562 582  
563 583 std::vector<std::reference_wrapper<HueLight>> test_lights =
... ...
hueplusplus/test/test_HueCommandAPI.cpp
... ... @@ -30,7 +30,8 @@ TEST(HueCommandAPI, PUTRequest) {
30 30 std::shared_ptr<MockHttpHandler> httpHandler =
31 31 std::make_shared<MockHttpHandler>();
32 32  
33   - HueCommandAPI api(getBridgeIp(), getBridgeUsername(), httpHandler);
  33 + HueCommandAPI api(getBridgeIp(), getBridgePort(), getBridgeUsername(),
  34 + httpHandler);
34 35 Json::Value request;
35 36 Json::Value result = Json::objectValue;
36 37 result["ok"] = true;
... ... @@ -102,7 +103,8 @@ TEST(HueCommandAPI, GETRequest) {
102 103 std::shared_ptr<MockHttpHandler> httpHandler =
103 104 std::make_shared<MockHttpHandler>();
104 105  
105   - HueCommandAPI api(getBridgeIp(), getBridgeUsername(), httpHandler);
  106 + HueCommandAPI api(getBridgeIp(), getBridgePort(), getBridgeUsername(),
  107 + httpHandler);
106 108 Json::Value request;
107 109 Json::Value result = Json::objectValue;
108 110 result["ok"] = true;
... ... @@ -174,7 +176,8 @@ TEST(HueCommandAPI, DELETERequest) {
174 176 std::shared_ptr<MockHttpHandler> httpHandler =
175 177 std::make_shared<MockHttpHandler>();
176 178  
177   - HueCommandAPI api(getBridgeIp(), getBridgeUsername(), httpHandler);
  179 + HueCommandAPI api(getBridgeIp(), getBridgePort(), getBridgeUsername(),
  180 + httpHandler);
178 181 Json::Value request;
179 182 Json::Value result = Json::objectValue;
180 183 result["ok"] = true;
... ...
hueplusplus/test/test_HueLight.cpp
... ... @@ -16,7 +16,8 @@ protected:
16 16 protected:
17 17 HueLightTest()
18 18 : handler(std::make_shared<MockHttpHandler>()),
19   - test_bridge(getBridgeIp(), getBridgeUsername(), handler) {
  19 + test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(),
  20 + handler) {
20 21 using namespace ::testing;
21 22 hue_bridge_state["lights"] = Json::Value(Json::objectValue);
22 23 hue_bridge_state["lights"]["1"] = Json::Value(Json::objectValue);
... ...
hueplusplus/test/testhelper.h
... ... @@ -6,6 +6,10 @@ inline std::string getBridgeIp() {
6 6 //!< decimal notation like "192.168.2.1"
7 7 }
8 8  
  9 +inline int getBridgePort() {
  10 + return 80;
  11 +}
  12 +
9 13 inline std::string getBridgeUsername() {
10 14 return "83b7780291a6ceffbe0bd049104df"; //!< Username that is ussed to access
11 15 //!< the fake hue bridge
... ...