diff --git a/hueplusplus/Hue.cpp b/hueplusplus/Hue.cpp index e6b1d37..d30dda7 100755 --- a/hueplusplus/Hue.cpp +++ b/hueplusplus/Hue.cpp @@ -49,12 +49,12 @@ std::vector HueFinder::FindBridges() const std::vector foundBridges; for (const std::pair &p : foundDevices) { - unsigned int found = p.second.find("IpBridge"); + size_t found = p.second.find("IpBridge"); if (found != std::string::npos) { HueIdentification bridge; - unsigned int start = p.first.find("//") + 2; - unsigned int length = p.first.find(":", start) - start; + size_t start = p.first.find("//") + 2; + size_t length = p.first.find(":", start) - start; bridge.ip = p.first.substr(start, length); std::string desc = http_handler->GETString("/description.xml", "application/xml", "", bridge.ip); std::smatch matchResult; @@ -238,6 +238,7 @@ HueLight& Hue::getLight(int id) else if (type == "LST001" || type == "LLC006" || type == "LLC007" || type == "LLC010" || type == "LLC011" || type == "LLC012" || type == "LLC013") { // HueColorLight Gamut A + //! \todo Check whether extended strategies are needed, because it is not clear, if these lights really have ct mode HueLight light = HueLight(ip, username, id, simpleBrightnessStrategy, simpleColorTemperatureStrategy, simpleColorHueStrategy, http_handler); light.colorType = ColorType::GAMUT_A; lights.emplace(id, light); @@ -263,6 +264,17 @@ HueLight& Hue::getLight(int id) throw(std::runtime_error("Could not determine HueLight type!")); } +bool Hue::removeLight(int id) +{ + Json::Value result = http_handler->DELETEJson("/api/"+username+"/lights/"+std::to_string(id), Json::objectValue, ip); + bool success = result.isArray() && !result[0].isNull() && result[0].isMember("success") && result[0]["success"] == "/lights/" + std::to_string(id) + " deleted"; + if (success && lights.count(id) != 0) + { + lights.erase(id); + } + return success; +} + std::vector> Hue::getAllLights() { refreshState(); diff --git a/hueplusplus/include/Hue.h b/hueplusplus/include/Hue.h index d98ce1b..4df330e 100755 --- a/hueplusplus/include/Hue.h +++ b/hueplusplus/include/Hue.h @@ -135,6 +135,13 @@ public: //! \return \ref HueLight that can be controlled HueLight& getLight(int id); + //! \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 + //! \return Bool that is true on success + bool removeLight(int id); + //! \brief Function that returns all light types that are associated with this bridge //! //! \return A map mapping light id's to light types for every light @@ -145,22 +152,28 @@ public: //! \return A vector containing references to every HueLight std::vector> getAllLights(); + //! \brief Function that sets the HttpHandler. + //! + //! The HttpHandler defines how specific commands that deal with bridge communication are executed + //! \param handler a HttpHandler of type \ref IHttpHandler + void setHttpHandler(std::shared_ptr handler) { http_handler = std::move(handler); }; + private: //! \brief Function that refreshes the local \ref state of the Hue bridge void refreshState(); private: - std::string ip; //!< IP-Address of the hue bridge in dotted decimal notation like "192.168.2.1" + std::string ip; //!< IP-Address of the hue bridge in dotted decimal notation like "192.168.2.1" std::string username; //!< Username that is ussed to access the hue bridge Json::Value state; //!< The state of the hue bridge as it is returned from it std::map< uint8_t, HueLight > lights; //!< Maps ids to HueLights that are controlled by this bridge - std::shared_ptr simpleBrightnessStrategy; //!< Strategy that is used for controlling the brightness of lights - std::shared_ptr simpleColorHueStrategy; //!< Strategy that is used for controlling the color of lights - std::shared_ptr extendedColorHueStrategy; //!< Strategy that is used for controlling the color of lights + std::shared_ptr simpleBrightnessStrategy; //!< Strategy that is used for controlling the brightness of lights + std::shared_ptr simpleColorHueStrategy; //!< Strategy that is used for controlling the color of lights + std::shared_ptr extendedColorHueStrategy; //!< Strategy that is used for controlling the color of lights std::shared_ptr simpleColorTemperatureStrategy; //!< Strategy that is used for controlling the color temperature of lights std::shared_ptr extendedColorTemperatureStrategy; //!< Strategy that is used for controlling the color temperature of lights - std::shared_ptr http_handler; + std::shared_ptr http_handler; //!< A IHttpHandler that is used to communicate with the bridge }; #endif