Commit f32be87270c902346e5ffd3deeb0e4c14499eed4
Committed by
Moritz Wirger
1 parent
f25df3b3
Add sharedState parameter to GetBridge.
Showing
2 changed files
with
7 additions
and
5 deletions
include/hueplusplus/Bridge.h
| ... | ... | @@ -85,12 +85,13 @@ public: |
| 85 | 85 | //! \brief Gets a Hue bridge based on its identification |
| 86 | 86 | //! |
| 87 | 87 | //! \param identification \ref BridgeIdentification that specifies a bridge |
| 88 | + //! \param sharedState Uses a single, shared cache for all objects on the bridge. | |
| 88 | 89 | //! \return \ref Bridge class object |
| 89 | 90 | //! \throws std::system_error when system or socket operations fail |
| 90 | 91 | //! \throws HueException when response contained no body or username could not be requested |
| 91 | 92 | //! \throws HueAPIResponseException when response contains an error |
| 92 | 93 | //! \throws nlohmann::json::parse_error when response could not be parsed |
| 93 | - Bridge GetBridge(const BridgeIdentification& identification); | |
| 94 | + Bridge GetBridge(const BridgeIdentification& identification, bool sharedState = false); | |
| 94 | 95 | |
| 95 | 96 | //! \brief Function that adds a username to the usernames map |
| 96 | 97 | //! | ... | ... |
src/Bridge.cpp
| ... | ... | @@ -75,15 +75,16 @@ std::vector<BridgeFinder::BridgeIdentification> BridgeFinder::FindBridges() cons |
| 75 | 75 | return foundBridges; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | -Bridge BridgeFinder::GetBridge(const BridgeIdentification& identification) | |
| 78 | +Bridge BridgeFinder::GetBridge(const BridgeIdentification& identification, bool sharedState) | |
| 79 | 79 | { |
| 80 | 80 | std::string normalizedMac = NormalizeMac(identification.mac); |
| 81 | 81 | auto pos = usernames.find(normalizedMac); |
| 82 | 82 | if (pos != usernames.end()) |
| 83 | 83 | { |
| 84 | - return Bridge(identification.ip, identification.port, pos->second, http_handler); | |
| 84 | + return Bridge( | |
| 85 | + identification.ip, identification.port, pos->second, http_handler, std::chrono::seconds(10), sharedState); | |
| 85 | 86 | } |
| 86 | - Bridge bridge(identification.ip, identification.port, "", http_handler); | |
| 87 | + Bridge bridge(identification.ip, identification.port, "", http_handler, std::chrono::seconds(10), sharedState); | |
| 87 | 88 | bridge.requestUsername(); |
| 88 | 89 | if (bridge.getUsername().empty()) |
| 89 | 90 | { |
| ... | ... | @@ -307,7 +308,7 @@ void Bridge::setHttpHandler(std::shared_ptr<const IHttpHandler> handler) |
| 307 | 308 | { |
| 308 | 309 | http_handler = handler; |
| 309 | 310 | stateCache = std::make_shared<APICache>("", HueCommandAPI(ip, port, username, handler), refreshDuration, nullptr); |
| 310 | - lightList = LightList(stateCache, "lights", refreshDuration,sharedState, | |
| 311 | + lightList = LightList(stateCache, "lights", refreshDuration, sharedState, | |
| 311 | 312 | [factory = LightFactory(stateCache->getCommandAPI(), refreshDuration)](int id, const nlohmann::json& state, |
| 312 | 313 | const std::shared_ptr<APICache>& baseCache) mutable { return factory.createLight(state, id, baseCache); }); |
| 313 | 314 | groupList = GroupList(stateCache, "groups", refreshDuration, sharedState); | ... | ... |