hueplusplus  1.0.0
Bridge.h
Go to the documentation of this file.
1 
23 #ifndef INCLUDE_HUEPLUSPLUS_HUE_H
24 #define INCLUDE_HUEPLUSPLUS_HUE_H
25 
26 #include <map>
27 #include <memory>
28 #include <string>
29 #include <utility>
30 #include <vector>
31 
32 #include "APICache.h"
33 #include "BridgeConfig.h"
34 #include "BrightnessStrategy.h"
35 #include "ColorHueStrategy.h"
37 #include "Group.h"
38 #include "HueCommandAPI.h"
39 #include "HueDeviceTypes.h"
40 #include "IHttpHandler.h"
41 #include "Light.h"
42 #include "ResourceList.h"
43 #include "Rule.h"
44 #include "Scene.h"
45 #include "Schedule.h"
46 #include "Sensor.h"
47 #include "SensorList.h"
48 #include "Utils.h"
49 
50 #include "json/json.hpp"
51 
53 namespace hueplusplus
54 {
55 // forward declarations
56 class Bridge;
57 
62 {
63 public:
65  {
66  std::string ip;
67  int port = 80;
68  std::string mac;
69  };
70 
71 public:
75  BridgeFinder(std::shared_ptr<const IHttpHandler> handler);
76 
83  std::vector<BridgeIdentification> findBridges() const;
84 
94  Bridge getBridge(const BridgeIdentification& identification, bool sharedState = false);
95 
100  void addUsername(const std::string& mac, const std::string& username);
101 
107  void addClientKey(const std::string& mac, const std::string& clientkey);
108 
114  const std::map<std::string, std::string>& getAllUsernames() const;
115 
118  static std::string normalizeMac(std::string input);
119 
120 private:
126  static std::string parseDescription(const std::string& description);
127 
128  std::map<std::string, std::string> usernames;
129  std::map<std::string, std::string> clientkeys;
131  std::shared_ptr<const IHttpHandler> http_handler;
133 };
134 
138 class Bridge
139 {
140  friend class BridgeFinder;
141 
142 public:
148 
149 public:
160  Bridge(const std::string& ip, const int port, const std::string& username,
161  std::shared_ptr<const IHttpHandler> handler, const std::string& clientkey = "",
162  std::chrono::steady_clock::duration refreshDuration = std::chrono::seconds(10), bool sharedState = false);
163 
173  void refresh();
174 
180  void setRefreshDuration(std::chrono::steady_clock::duration refreshDuration);
181 
185  std::string getBridgeIP() const;
186 
190  bool startStreaming(std::string group_identifier);
191 
195  bool stopStreaming(std::string group_identifier);
196 
200  int getBridgePort() const;
201 
211  std::string requestUsername();
212 
216  std::string getUsername() const;
217 
221  std::string getClientKey() const;
222 
226  void setIP(const std::string& ip);
227 
232  void setPort(const int port);
233 
235  BridgeConfig& config();
238  const BridgeConfig& config() const;
239 
241  LightList& lights();
244  const LightList& lights() const;
245 
247  GroupList& groups();
250  const GroupList& groups() const;
251 
253  ScheduleList& schedules();
256  const ScheduleList& schedules() const;
257 
259  SceneList& scenes();
262  const SceneList& scenes() const;
263 
265  SensorList& sensors();
268  const SensorList& sensors() const;
269 
271  RuleList& rules();
274  const RuleList& rules() const;
275 
276 private:
284  void setHttpHandler(std::shared_ptr<const IHttpHandler> handler);
285 
286 private:
287  std::string ip;
288  std::string username;
290  std::string clientkey;
291  int port;
292 
293  std::shared_ptr<const IHttpHandler> http_handler;
294  std::chrono::steady_clock::duration refreshDuration;
296  std::shared_ptr<APICache> stateCache;
297  detail::MakeCopyable<LightList> lightList;
298  detail::MakeCopyable<GroupList> groupList;
299  detail::MakeCopyable<ScheduleList> scheduleList;
300  detail::MakeCopyable<SceneList> sceneList;
301  detail::MakeCopyable<SensorList> sensorList;
302  detail::MakeCopyable<RuleList> ruleList;
303  detail::MakeCopyable<BridgeConfig> bridgeConfig;
304  bool sharedState;
305 };
306 } // namespace hueplusplus
307 
308 #endif
void addClientKey(const std::string &mac, const std::string &clientkey)
Function that adds a client key to the clientkeys map.
Definition: Bridge.cpp:114
Parameters for creating a new Schedule.
Definition: Schedule.h:150
Handles a ResourceList where Resources can be added by the user.
Definition: ResourceList.h:285
Bridge getBridge(const BridgeIdentification &identification, bool sharedState=false)
Gets a Hue bridge based on its identification.
Definition: Bridge.cpp:78
Namespace for the hueplusplus library.
Definition: Action.h:27
std::string mac
Definition: Bridge.h:68
void addUsername(const std::string &mac, const std::string &username)
Function that adds a username to the usernames map.
Definition: Bridge.cpp:109
Parameters for creating a new Rule.
Definition: Rule.h:150
Handles a group list with the special group 0.
Definition: ResourceList.h:331
Definition: Bridge.h:61
const std::map< std::string, std::string > & getAllUsernames() const
Function that returns a map of mac addresses and usernames.
Definition: Bridge.cpp:119
Parameters for creating a new Scene.
Definition: Scene.h:267
const std::string username
Definition: BridgeSetup.cpp:47
Bridge class for a bridge.
Definition: Bridge.h:138
static std::string normalizeMac(std::string input)
Normalizes mac address to plain hex number.
Definition: Bridge.cpp:124
std::vector< BridgeIdentification > findBridges() const
Finds all bridges in the network and returns them.
Definition: Bridge.cpp:43
General bridge configuration properties.
Definition: BridgeConfig.h:55
Handles a list of Sensors with type specific getters.
Definition: SensorList.h:33
BridgeFinder(std::shared_ptr< const IHttpHandler > handler)
Constructor of BridgeFinder class.
Definition: Bridge.cpp:41
std::string ip
Definition: Bridge.h:66
Handles a ResourceList of physical devices which can be searched for.
Definition: ResourceList.h:239