Bridge.h
Go to the documentation of this file.
1 
20 #pragma once
21 
22 #include "Device.h"
23 #include "Stats.h"
24 #include <Network/HttpServer.h>
25 #include <Data/WebConstants.h>
26 #include <SimpleTimer.h>
27 #include <Network/UPnP/schemas-upnp-org/ClassGroup.h>
28 
29 namespace Hue
30 {
31 enum class Model {
32  LWB004,
33  LWB007,
34 };
35 
39 struct User {
41  uint16_t count{0};
42  bool authorized{false};
43 };
44 
49 
50 class Bridge : public UPnP::schemas_upnp_org::device::Basic1Template<Bridge>
51 {
52 public:
56  struct Config {
57  enum class Type {
58  AuthorizeUser,
59  RevokeUser,
60  };
61 
65  };
66 
74 
85 
90  Bridge(Hue::Device::Enumerator& devices) : Basic1Template(), devices(devices)
91  {
92  }
93 
98  void configure(const Config& config);
99 
108  void enablePairing(bool enable)
109  {
110  pairingEnabled = enable;
111  }
112 
114  {
115  configDelegate = delegate;
116  }
117 
119  {
120  stateChangeDelegate = delegate;
121  }
122 
123  void begin();
124 
129  const Stats& getStats()
130  {
131  return stats;
132  }
133 
137  void resetStats()
138  {
139  memset(&stats, 0, sizeof(stats));
140  }
141 
146  const UserMap& getUsers() const
147  {
148  return users;
149  }
150 
155  void getStatusInfo(JsonObject json);
156 
162  {
163  if(stateChangeDelegate) {
164  stateChangeDelegate(device, changed);
165  }
166  }
167 
168  /* UPnP::Device */
169 
170  String getField(Field desc) const override;
171 
172  bool formatMessage(SSDP::Message& msg, SSDP::MessageSpec& ms) override;
173  bool onHttpRequest(HttpServerConnection& connection) override;
174 
175 private:
176  void createUser(JsonObjectConst request, JsonDocument& result, const String& path);
177  bool validateUser(const char* userName);
178  void handleApiRequest(HttpServerConnection& connection);
179 
180 private:
181  UserMap users;
182  bool pairingEnabled = false;
183  Hue::Device::Enumerator& devices;
184  ConfigDelegate configDelegate;
185  StateChangeDelegate stateChangeDelegate;
186  Stats stats;
187 };
188 
189 } // namespace Hue
Definition: Bridge.h:29
void onConfigChange(ConfigDelegate delegate)
Definition: Bridge.h:113
String name
Randomly generated key.
Definition: Bridge.h:64
Definition: Bridge.h:50
Bridge(Hue::Device::Enumerator &devices)
Constructor.
Definition: Bridge.h:90
Definition: Libraries/HueEmulator/src/include/Hue/Device.h:92
Definition: Bridge.h:56
String deviceType
How device identifies itself.
Definition: Bridge.h:63
Definition: HttpServerConnection.h:33
The String class.
Definition: WString.h:136
Type type
Configuration action to perform.
Definition: Bridge.h:62
Definition: Stats.h:27
void enablePairing(bool enable)
Enable creation of new users.
Definition: Bridge.h:108
Json json
Model
Definition: Bridge.h:31
const UserMap & getUsers() const
Access the list of users.
Definition: Bridge.h:146
Type
Definition: Bridge.h:57
String deviceType
How the user identifies themselves.
Definition: Bridge.h:40
Manage a set of bit values using enumeration.
Definition: BitSet.h:43
Dimmable white.
void resetStats()
Clear the bridge statistics.
Definition: Bridge.h:137
const Stats & getStats()
Get bridge statistics.
Definition: Bridge.h:129
void deviceStateChanged(const Hue::Device &device, Hue::Device::Attributes changed)
Devices call this method when their state has been updated.
Definition: Bridge.h:161
Information about user.
Definition: Bridge.h:39
void onStateChanged(StateChangeDelegate delegate)
Definition: Bridge.h:118
Abstract class to manage a list of devices.
Definition: Libraries/HueEmulator/src/include/Hue/Device.h:125