Commit 77890282210c6785c350c7de77219064a413fd95

Authored by Jojo-1000
Committed by Jan
1 parent ce79be36

Remove redundant ip parameter from Hue::requestUsername.

hueplusplus/Hue.cpp
... ... @@ -79,7 +79,7 @@ Hue HueFinder::GetBridge(const HueIdentification& identification)
79 79 return Hue(identification.ip, identification.port, pos->second, http_handler);
80 80 }
81 81 Hue bridge(identification.ip, identification.port, "", http_handler);
82   - bridge.requestUsername(identification.ip);
  82 + bridge.requestUsername();
83 83 if (bridge.getUsername().empty())
84 84 {
85 85 std::cerr << "Failed to request username for ip " << identification.ip << std::endl;
... ... @@ -156,7 +156,7 @@ int Hue::getBridgePort()
156 156 return port;
157 157 }
158 158  
159   -std::string Hue::requestUsername(const std::string& ip)
  159 +std::string Hue::requestUsername()
160 160 {
161 161 std::cout << "Please press the link Button! You've got 35 secs!\n"; // when the link
162 162 // button was
... ... @@ -187,7 +187,6 @@ std::string Hue::requestUsername(const std::string&amp; ip)
187 187 {
188 188 // [{"success":{"username": "<username>"}}]
189 189 username = jsonUser;
190   - this->ip = ip;
191 190 // Update commands with new username and ip
192 191 commands = HueCommandAPI(ip, port, username, http_handler);
193 192 std::cout << "Success! Link button was pressed!\n";
... ...
hueplusplus/include/Hue.h
... ... @@ -98,7 +98,7 @@ public:
98 98 private:
99 99 //! \brief Parses mac address from description.xml
100 100 //!
101   - //! \param description Content of description.xml file as returned by GET request.
  101 + //! \param description Content of description.xml file as returned by GET request.
102 102 //! \returns Content of xml element \c serialNumber if description matches a Hue bridge, otherwise an empty string.
103 103 static std::string ParseDescription(const std::string& description);
104 104  
... ... @@ -115,10 +115,11 @@ class Hue
115 115 public:
116 116 //! \brief Constructor of Hue class
117 117 //!
118   - //! decimal notation like "192.168.2.1" \param port Port of the hue bridge
  118 + //! \param ip IP address in dotted decimal notation like "192.168.2.1"
  119 + //! \param port Port of the hue bridge
119 120 //! \param username String that specifies the username that is used to control
120   - //! the bridge. This needs to be acquired in \ref requestUsername \param handler
121   - //! HttpHandler of type \ref IHttpHandler for communication with the bridge
  121 + //! the bridge. This needs to be acquired in \ref requestUsername
  122 + //! \param handler HttpHandler for communication with the bridge
122 123 Hue(const std::string& ip, const int port, const std::string& username,
123 124 std::shared_ptr<const IHttpHandler> handler);
124 125  
... ... @@ -134,17 +135,16 @@ public:
134 135  
135 136 //! \brief Send a username request to the Hue bridge.
136 137 //!
137   - //! Blocks for about 30 seconds and 5 seconds to prepare.
138   - //! It automatically sets the \ref username variable according to the username received and returns the username received.
139   - //! This function should only be called once to acquire a username to control the bridge and the username
  138 + //! Blocks for about 30 seconds and 5 seconds to prepare.
  139 + //! It automatically sets the \ref username variable according to the username received and returns the username
  140 + //! received. This function should only be called once to acquire a username to control the bridge and the username
140 141 //! should be saved for future use.
141   - //! \param ip String that specifies the ip (in dotted decimal notation like "192.168.2.1") the request is send to
142 142 //! \return username for API usage
143 143 //! \throws std::system_error when system or socket operations fail
144 144 //! \throws HueException when response contained no body
145 145 //! \throws HueAPIResponseException when response contains an error except link button not pressed.
146 146 //! \throws nlohmann::json::parse_error when response could not be parsed
147   - std::string requestUsername(const std::string& ip);
  147 + std::string requestUsername();
148 148  
149 149 //! \brief Function that returns the \ref username
150 150 //!
... ... @@ -174,8 +174,8 @@ public:
174 174  
175 175 //! \brief Function to remove a light from the bridge
176 176 //!
177   - //! \attention Any use of the light after it was successfully removed results in undefined behavior
178   - //! \param id Id of the light to remove
  177 + //! \attention Any use of the light after it was successfully removed results in undefined behavior
  178 + //! \param id Id of the light to remove
179 179 //! \return true on success
180 180 //! \throws std::system_error when system or socket operations fail
181 181 //! \throws HueException when response contains no body
... ... @@ -245,7 +245,7 @@ public:
245 245 {
246 246 http_handler = std::move(handler);
247 247 commands = HueCommandAPI(ip, port, username, http_handler);
248   - };
  248 + }
249 249  
250 250 private:
251 251 //! \brief Function that refreshes the local \ref state of the Hue bridge
... ...
hueplusplus/include/HueCommandAPI.h
... ... @@ -38,10 +38,11 @@ public:
38 38 //! \brief Construct from ip, username and HttpHandler
39 39 //!
40 40 //! \param ip ip address of the Hue bridge in dotted decimal notation like "192.168.2.1"
41   - //! \param username username that is used to control the bridge
42 41 //! \param port of the hue bridge
  42 + //! \param username username that is used to control the bridge
43 43 //! \param handler HttpHandler for communication with the bridge
44   - HueCommandAPI(const std::string& ip, const std::string& username, std::shared_ptr<const IHttpHandler> httpHandler);
  44 + HueCommandAPI(
  45 + const std::string& ip, int port, const std::string& username, std::shared_ptr<const IHttpHandler> httpHandler);
45 46  
46 47 //! \brief Copy construct from other HueCommandAPI
47 48 //! \note All copies refer to the same timeout data, so even calls from different objects will be delayed
... ...
hueplusplus/test/test_Hue.cpp
... ... @@ -193,7 +193,7 @@ TEST(Hue, requestUsername)
193 193  
194 194 Hue test_bridge(getBridgeIp(), getBridgePort(), "", handler);
195 195  
196   - test_bridge.requestUsername(test_bridge.getBridgeIP());
  196 + test_bridge.requestUsername();
197 197 EXPECT_EQ(test_bridge.getUsername(), "") << "Bridge username not matching";
198 198  
199 199 nlohmann::json user_ret_suc;
... ... @@ -207,7 +207,7 @@ TEST(Hue, requestUsername)
207 207  
208 208 test_bridge = Hue(getBridgeIp(), getBridgePort(), "", handler);
209 209  
210   - test_bridge.requestUsername(test_bridge.getBridgeIP());
  210 + test_bridge.requestUsername();
211 211  
212 212 EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp()) << "Bridge IP not matching";
213 213 EXPECT_EQ(test_bridge.getUsername(), getBridgeUsername()) << "Bridge username not matching";
... ...