From f32be87270c902346e5ffd3deeb0e4c14499eed4 Mon Sep 17 00:00:00 2001 From: Jojo-1000 <33495614+Jojo-1000@users.noreply.github.com> Date: Sat, 13 Mar 2021 19:56:38 +0100 Subject: [PATCH] Add sharedState parameter to GetBridge. --- include/hueplusplus/Bridge.h | 3 ++- src/Bridge.cpp | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/hueplusplus/Bridge.h b/include/hueplusplus/Bridge.h index b194ffb..4232fe3 100644 --- a/include/hueplusplus/Bridge.h +++ b/include/hueplusplus/Bridge.h @@ -85,12 +85,13 @@ public: //! \brief Gets a Hue bridge based on its identification //! //! \param identification \ref BridgeIdentification that specifies a bridge + //! \param sharedState Uses a single, shared cache for all objects on the bridge. //! \return \ref Bridge class object //! \throws std::system_error when system or socket operations fail //! \throws HueException when response contained no body or username could not be requested //! \throws HueAPIResponseException when response contains an error //! \throws nlohmann::json::parse_error when response could not be parsed - Bridge GetBridge(const BridgeIdentification& identification); + Bridge GetBridge(const BridgeIdentification& identification, bool sharedState = false); //! \brief Function that adds a username to the usernames map //! diff --git a/src/Bridge.cpp b/src/Bridge.cpp index 7a561a6..6ef7f7b 100644 --- a/src/Bridge.cpp +++ b/src/Bridge.cpp @@ -75,15 +75,16 @@ std::vector BridgeFinder::FindBridges() cons return foundBridges; } -Bridge BridgeFinder::GetBridge(const BridgeIdentification& identification) +Bridge BridgeFinder::GetBridge(const BridgeIdentification& identification, bool sharedState) { std::string normalizedMac = NormalizeMac(identification.mac); auto pos = usernames.find(normalizedMac); if (pos != usernames.end()) { - return Bridge(identification.ip, identification.port, pos->second, http_handler); + return Bridge( + identification.ip, identification.port, pos->second, http_handler, std::chrono::seconds(10), sharedState); } - Bridge bridge(identification.ip, identification.port, "", http_handler); + Bridge bridge(identification.ip, identification.port, "", http_handler, std::chrono::seconds(10), sharedState); bridge.requestUsername(); if (bridge.getUsername().empty()) { @@ -307,7 +308,7 @@ void Bridge::setHttpHandler(std::shared_ptr handler) { http_handler = handler; stateCache = std::make_shared("", HueCommandAPI(ip, port, username, handler), refreshDuration, nullptr); - lightList = LightList(stateCache, "lights", refreshDuration,sharedState, + lightList = LightList(stateCache, "lights", refreshDuration, sharedState, [factory = LightFactory(stateCache->getCommandAPI(), refreshDuration)](int id, const nlohmann::json& state, const std::shared_ptr& baseCache) mutable { return factory.createLight(state, id, baseCache); }); groupList = GroupList(stateCache, "groups", refreshDuration, sharedState); -- libgit2 0.21.4