diff --git a/hueplusplus/Hue.cpp b/hueplusplus/Hue.cpp index fee5e16..f9462c9 100644 --- a/hueplusplus/Hue.cpp +++ b/hueplusplus/Hue.cpp @@ -79,7 +79,7 @@ Hue HueFinder::GetBridge(const HueIdentification& identification) return Hue(identification.ip, identification.port, pos->second, http_handler); } Hue bridge(identification.ip, identification.port, "", http_handler); - bridge.requestUsername(identification.ip); + bridge.requestUsername(); if (bridge.getUsername().empty()) { std::cerr << "Failed to request username for ip " << identification.ip << std::endl; @@ -156,7 +156,7 @@ int Hue::getBridgePort() return port; } -std::string Hue::requestUsername(const std::string& ip) +std::string Hue::requestUsername() { std::cout << "Please press the link Button! You've got 35 secs!\n"; // when the link // button was @@ -187,7 +187,6 @@ std::string Hue::requestUsername(const std::string& ip) { // [{"success":{"username": ""}}] username = jsonUser; - this->ip = ip; // Update commands with new username and ip commands = HueCommandAPI(ip, port, username, http_handler); std::cout << "Success! Link button was pressed!\n"; diff --git a/hueplusplus/include/Hue.h b/hueplusplus/include/Hue.h index 18cda3a..2765a4f 100644 --- a/hueplusplus/include/Hue.h +++ b/hueplusplus/include/Hue.h @@ -98,7 +98,7 @@ public: private: //! \brief Parses mac address from description.xml //! - //! \param description Content of description.xml file as returned by GET request. + //! \param description Content of description.xml file as returned by GET request. //! \returns Content of xml element \c serialNumber if description matches a Hue bridge, otherwise an empty string. static std::string ParseDescription(const std::string& description); @@ -115,10 +115,11 @@ class Hue public: //! \brief Constructor of Hue class //! - //! decimal notation like "192.168.2.1" \param port Port of the hue bridge + //! \param ip IP address in dotted decimal notation like "192.168.2.1" + //! \param port Port of the hue bridge //! \param username String that specifies the username that is used to control - //! the bridge. This needs to be acquired in \ref requestUsername \param handler - //! HttpHandler of type \ref IHttpHandler for communication with the bridge + //! the bridge. This needs to be acquired in \ref requestUsername + //! \param handler HttpHandler for communication with the bridge Hue(const std::string& ip, const int port, const std::string& username, std::shared_ptr handler); @@ -134,17 +135,16 @@ public: //! \brief Send a username request to the Hue bridge. //! - //! Blocks for about 30 seconds and 5 seconds to prepare. - //! It automatically sets the \ref username variable according to the username received and returns the username received. - //! This function should only be called once to acquire a username to control the bridge and the username + //! Blocks for about 30 seconds and 5 seconds to prepare. + //! It automatically sets the \ref username variable according to the username received and returns the username + //! received. This function should only be called once to acquire a username to control the bridge and the username //! should be saved for future use. - //! \param ip String that specifies the ip (in dotted decimal notation like "192.168.2.1") the request is send to //! \return username for API usage //! \throws std::system_error when system or socket operations fail //! \throws HueException when response contained no body //! \throws HueAPIResponseException when response contains an error except link button not pressed. //! \throws nlohmann::json::parse_error when response could not be parsed - std::string requestUsername(const std::string& ip); + std::string requestUsername(); //! \brief Function that returns the \ref username //! @@ -174,8 +174,8 @@ public: //! \brief Function to remove a light from the bridge //! - //! \attention Any use of the light after it was successfully removed results in undefined behavior - //! \param id Id of the light to remove + //! \attention Any use of the light after it was successfully removed results in undefined behavior + //! \param id Id of the light to remove //! \return true on success //! \throws std::system_error when system or socket operations fail //! \throws HueException when response contains no body @@ -245,7 +245,7 @@ public: { http_handler = std::move(handler); commands = HueCommandAPI(ip, port, username, http_handler); - }; + } private: //! \brief Function that refreshes the local \ref state of the Hue bridge diff --git a/hueplusplus/include/HueCommandAPI.h b/hueplusplus/include/HueCommandAPI.h index 66de931..e73dfbb 100644 --- a/hueplusplus/include/HueCommandAPI.h +++ b/hueplusplus/include/HueCommandAPI.h @@ -38,10 +38,11 @@ public: //! \brief Construct from ip, username and HttpHandler //! //! \param ip ip address of the Hue bridge in dotted decimal notation like "192.168.2.1" - //! \param username username that is used to control the bridge //! \param port of the hue bridge + //! \param username username that is used to control the bridge //! \param handler HttpHandler for communication with the bridge - HueCommandAPI(const std::string& ip, const std::string& username, std::shared_ptr httpHandler); + HueCommandAPI( + const std::string& ip, int port, const std::string& username, std::shared_ptr httpHandler); //! \brief Copy construct from other HueCommandAPI //! \note All copies refer to the same timeout data, so even calls from different objects will be delayed diff --git a/hueplusplus/test/test_Hue.cpp b/hueplusplus/test/test_Hue.cpp index f9a261b..a053515 100644 --- a/hueplusplus/test/test_Hue.cpp +++ b/hueplusplus/test/test_Hue.cpp @@ -193,7 +193,7 @@ TEST(Hue, requestUsername) Hue test_bridge(getBridgeIp(), getBridgePort(), "", handler); - test_bridge.requestUsername(test_bridge.getBridgeIP()); + test_bridge.requestUsername(); EXPECT_EQ(test_bridge.getUsername(), "") << "Bridge username not matching"; nlohmann::json user_ret_suc; @@ -207,7 +207,7 @@ TEST(Hue, requestUsername) test_bridge = Hue(getBridgeIp(), getBridgePort(), "", handler); - test_bridge.requestUsername(test_bridge.getBridgeIP()); + test_bridge.requestUsername(); EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp()) << "Bridge IP not matching"; EXPECT_EQ(test_bridge.getUsername(), getBridgeUsername()) << "Bridge username not matching";