hueplusplus  1.0.0
Group.h
Go to the documentation of this file.
1 
23 #ifndef INCLUDE_HUEPLUSPLUS_GROUP_H
24 #define INCLUDE_HUEPLUSPLUS_GROUP_H
25 
26 #include <string>
27 #include <vector>
28 
29 #include "APICache.h"
30 #include "Action.h"
31 #include "HueCommandAPI.h"
32 #include "StateTransaction.h"
33 
34 #include "json/json.hpp"
35 
36 namespace hueplusplus
37 {
41 class Group
42 {
43 public:
47  Group(int id, const std::shared_ptr<APICache>& baseCache);
53  Group(int id, const HueCommandAPI& commands, std::chrono::steady_clock::duration refreshDuration, const nlohmann::json& currentState);
54 
62  void refresh(bool force = false);
63 
66  void setRefreshDuration(std::chrono::steady_clock::duration refreshDuration);
67 
70 
72  int getId() const;
73 
75  std::string getName() const;
76 
88  std::string getType() const;
89 
92  std::vector<int> getLightIds() const;
93 
97  void setName(const std::string& name);
104  void setLights(const std::vector<int>& ids);
105 
108  std::string getRoomType() const;
116  void setRoomType(const std::string& type);
117 
120  std::string getModelId() const;
121 
125  std::string getUniqueId() const;
126 
133  bool getAllOn();
134 
138  bool getAllOn() const;
139 
146  bool getAnyOn();
147 
151  bool getAnyOn() const;
152 
158 
165  bool getActionOn();
166 
170  bool getActionOn() const;
171 
178  std::pair<uint16_t, uint8_t> getActionHueSaturation();
179 
183  std::pair<uint16_t, uint8_t> getActionHueSaturation() const;
184 
191  unsigned int getActionBrightness();
192 
196  unsigned int getActionBrightness() const;
197 
204  unsigned int getActionColorTemperature();
205 
209  unsigned int getActionColorTemperature() const;
210 
217  std::pair<float, float> getActionColorXY();
218 
222  std::pair<float, float> getActionColorXY() const;
223 
231  std::string getActionColorMode();
232 
237  std::string getActionColorMode() const;
238 
240 
243 
252 
255  void setOn(bool on, uint8_t transition = 4);
258  void setBrightness(uint8_t brightness, uint8_t transition = 4);
261  void setColor(const HueSaturation& hueSat, uint8_t transition = 4);
264  void setColor(const XYBrightness& xy, uint8_t transition = 4);
267  void setColorTemperature(unsigned int mired, uint8_t transition = 4);
270  void setColorLoop(bool on, uint8_t transition = 4);
271 
276  void setScene(const std::string& scene);
277 
283  Action createSceneAction(const std::string& scene) const;
284 
286 
287 protected:
298  nlohmann::json sendPutRequest(const std::string& subPath, const nlohmann::json& request, FileInfo fileInfo);
299 
300 protected:
301  int id;
303 };
304 
311 {
312 public:
318  static CreateGroup LightGroup(const std::vector<int>& lights, const std::string& name = "");
326  static CreateGroup Room(
327  const std::vector<int>& lights, const std::string& name = "", const std::string& roomType = "");
334  static CreateGroup Entertainment(const std::vector<int>& lights, const std::string& name = "");
335 
341  static CreateGroup Zone(const std::vector<int>& lights, const std::string& name = "");
342 
345  nlohmann::json getRequest() const;
346 
347 protected:
353  CreateGroup(
354  const std::vector<int>& lights, const std::string& name, const std::string& type, const std::string& roomType);
355 
356 private:
357  std::vector<int> lights;
358  std::string name;
359  std::string type;
360  std::string roomType;
361 };
362 } // namespace hueplusplus
363 
364 #endif
int getId() const
Get the group id.
Definition: Group.cpp:36
StateTransaction transaction()
Create a transaction for this group.
Definition: Group.cpp:163
Parameters necessary for creating a new Group.
Definition: Group.h:310
void setColor(const HueSaturation &hueSat, uint8_t transition=4)
Convenience function to set hue and saturation.
Definition: Group.cpp:179
Definition: HueCommandAPI.h:37
void setName(const std::string &name)
Set group name.
Definition: Group.cpp:67
Action executed by the bridge, e.g. as a Schedule command.
Definition: Action.h:35
Namespace for the hueplusplus library.
Definition: Action.h:27
Action createSceneAction(const std::string &scene) const
Get Action to set scene.
Definition: Group.cpp:204
Group(int id, const std::shared_ptr< APICache > &baseCache)
Creates group with shared cache.
Definition: Group.cpp:7
void setRefreshDuration(std::chrono::steady_clock::duration refreshDuration)
Sets custom refresh interval for this group.
Definition: Group.cpp:30
Caches API GET requests and refreshes regularly.
Definition: APICache.h:37
void setOn(bool on, uint8_t transition=4)
Convenience function to turn lights on.
Definition: Group.cpp:169
void setScene(const std::string &scene)
Recall scene for the group.
Definition: Group.cpp:199
void refresh(bool force=false)
Refreshes internal cached state.
Definition: Group.cpp:18
std::string getType() const
Get the group type.
Definition: Group.cpp:46
void setRoomType(const std::string &type)
Set room type, only for type room.
Definition: Group.cpp:222
bool getActionOn()
Get on state of one light in the group.
Definition: Group.cpp:103
Contains information about error location, use CURRENT_FILE_INFO to create.
Definition: HueException.h:34
std::string getRoomType() const
Get room type, only for type room.
Definition: Group.cpp:217
void setLights(const std::vector< int > &ids)
Set group lights.
Definition: Group.cpp:74
void setBrightness(uint8_t brightness, uint8_t transition=4)
Convenience function to set brightness.
Definition: Group.cpp:174
bool getAllOn()
Get whether all lights are on.
Definition: Group.cpp:85
Color and brightness in CIE.
Definition: ColorUnits.h:62
unsigned int getActionBrightness()
Get brightness of one light in the group.
Definition: Group.cpp:125
std::pair< uint16_t, uint8_t > getActionHueSaturation()
Get hue and saturation of one light in the group.
Definition: Group.cpp:112
void setColorLoop(bool on, uint8_t transition=4)
Convenience function to set color loop.
Definition: Group.cpp:194
std::string getName() const
Get the group name.
Definition: Group.cpp:41
bool getAnyOn()
Get whether any light is on.
Definition: Group.cpp:94
Transaction class which can be used for either light or group state.
Definition: StateTransaction.h:61
int id
Definition: Group.h:301
std::pair< float, float > getActionColorXY()
Get color coordinates of one light in the group.
Definition: Group.cpp:143
void setColorTemperature(unsigned int mired, uint8_t transition=4)
Convenience function to set color temperature.
Definition: Group.cpp:189
std::vector< int > getLightIds() const
Get lights in the group.
Definition: Group.cpp:51
nlohmann::json sendPutRequest(const std::string &subPath, const nlohmann::json &request, FileInfo fileInfo)
Utility function to send a put request to the group.
Definition: Group.cpp:212
Class for Groups of lights.
Definition: Group.h:41
std::string getUniqueId() const
Get luminaire model id, only for type luminaire or lightsource.
Definition: Group.cpp:233
APICache state
Definition: Group.h:302
Color in hue and saturation.
Definition: ColorUnits.h:31
unsigned int getActionColorTemperature()
Get color temperature of one light in the group.
Definition: Group.cpp:134
std::string getModelId() const
Get luminaire model id, only for type luminaire.
Definition: Group.cpp:228
std::string getActionColorMode()
Get color mode of one light in the group.
Definition: Group.cpp:154