hueplusplus  1.0.0
Scene.h
Go to the documentation of this file.
1 
22 #ifndef INCLUDE_HUEPLUSPLUS_SCENE_H
23 #define INCLUDE_HUEPLUSPLUS_SCENE_H
24 
25 #include <map>
26 #include <string>
27 #include <vector>
28 
29 #include <json/json.hpp>
30 
31 #include "APICache.h"
32 #include "ColorUnits.h"
33 #include "TimePattern.h"
34 
35 namespace hueplusplus
36 {
39 {
40 public:
43  explicit LightState(const nlohmann::json& state);
44 
46  bool isOn() const;
47 
49  bool hasBrightness() const;
52  int getBrightness() const;
53 
55  bool hasHueSat() const;
58  HueSaturation getHueSat() const;
59 
61  bool hasXY() const;
64  XYBrightness getXY() const;
65 
67  bool hasCt() const;
70  int getCt() const;
71 
73  bool hasEffect() const;
76  bool getColorloop() const;
77 
80  int getTransitionTime() const;
81 
83  nlohmann::json toJson() const;
84 
86  bool operator==(const LightState& other) const;
88  bool operator!=(const LightState& other) const;
89 
90 private:
91  nlohmann::json state;
92 };
93 
96 {
97 public:
98  LightStateBuilder& setOn(bool on);
99  LightStateBuilder& setBrightness(int brightness);
100  LightStateBuilder& setHueSat(const HueSaturation& hueSat);
101  LightStateBuilder& setXY(const XY& xy);
102  LightStateBuilder& setCt(int mired);
103  LightStateBuilder& setColorloop(bool enabled);
104  LightStateBuilder& setTransitionTime(int time);
105 
106  LightState create();
107 
108 private:
109  nlohmann::json state;
110 };
111 
115 class Scene
116 {
117 public:
119  enum class Type
120  {
121  lightScene,
122  groupScene
123  };
124 
125 public:
129  Scene(const std::string& id, const std::shared_ptr<APICache>& baseCache);
135  Scene(const std::string& id, const HueCommandAPI& commands, std::chrono::steady_clock::duration refreshDuration, const nlohmann::json& currentState);
136 
144  void refresh(bool force = false);
145 
148  void setRefreshDuration(std::chrono::steady_clock::duration refreshDuration);
149 
151  std::string getId() const;
155  std::string getName() const;
163  void setName(const std::string& name);
167  Type getType() const;
168 
171  int getGroupId() const;
172 
176  std::vector<int> getLightIds() const;
185  void setLightIds(const std::vector<int>& ids);
186 
188  std::string getOwner() const;
190  bool getRecycle() const;
192  bool isLocked() const;
193 
195  std::string getAppdata() const;
197  int getAppdataVersion() const;
205  void setAppdata(const std::string& data, int version);
206 
210  std::string getPicture() const;
212  time::AbsoluteTime getLastUpdated() const;
216  int getVersion() const;
217 
220  std::map<int, LightState> getLightStates() const;
228  void setLightStates(const std::map<int, LightState>& states);
229 
235  void storeCurrentLightState();
242  void storeCurrentLightState(int transition);
243 
249  void recall();
250 
251 private:
257  void sendPutRequest(const std::string& path, const nlohmann::json& request, FileInfo fileInfo);
258 
259 private:
260  std::string id;
261  APICache state;
262 };
263 
268 {
269 public:
272  CreateScene& setName(const std::string& name);
278  CreateScene& setGroupId(int id);
282  CreateScene& setLightIds(const std::vector<int>& ids);
286  CreateScene& setRecycle(bool recycle);
289  CreateScene& setAppdata(const std::string& data, int version);
294  CreateScene& setLightStates(const std::map<int, LightState>& states);
295 
298  nlohmann::json getRequest() const;
299 
300 private:
301  nlohmann::json request;
302 };
303 } // namespace hueplusplus
304 
305 #endif
Type
Type of the scen.
Definition: Scene.h:119
bool hasBrightness() const
Get whether a brightness is stored.
Definition: Scene.cpp:34
Definition: HueCommandAPI.h:37
bool isOn() const
Get whether the light is on.
Definition: Scene.cpp:29
int getTransitionTime() const
Get transition time to this light state.
Definition: Scene.cpp:85
Namespace for the hueplusplus library.
Definition: Action.h:27
Caches API GET requests and refreshes regularly.
Definition: APICache.h:37
bool operator==(const LightState &other) const
Equality comparison.
Definition: Scene.cpp:95
bool hasHueSat() const
Get whether hue and saturation is stored.
Definition: Scene.cpp:44
Contains information about error location, use CURRENT_FILE_INFO to create.
Definition: HueException.h:34
Parameters for creating a new Scene.
Definition: Scene.h:267
One-time, absolute time point.
Definition: TimePattern.h:72
int getCt() const
Get color temperature of the light.
Definition: Scene.cpp:70
Color and brightness in CIE.
Definition: ColorUnits.h:62
int getBrightness() const
Get brightness of the light.
Definition: Scene.cpp:39
bool getColorloop() const
Get whether colorloop effect is active.
Definition: Scene.cpp:80
bool hasEffect() const
Get whether effect is stored.
Definition: Scene.cpp:75
nlohmann::json toJson() const
Convert to json representation.
Definition: Scene.cpp:90
Color in CIE x and y coordinates.
Definition: ColorUnits.h:47
bool operator!=(const LightState &other) const
Inequality comparison.
Definition: Scene.cpp:100
HueSaturation getHueSat() const
Get hue and saturation of the light.
Definition: Scene.cpp:49
Immutable state of a light.
Definition: Scene.h:38
bool hasXY() const
Get whether xy color is stored.
Definition: Scene.cpp:54
Builder to create LightState.
Definition: Scene.h:95
Color in hue and saturation.
Definition: ColorUnits.h:31
LightState(const nlohmann::json &state)
Create LightState from json.
Definition: Scene.cpp:27
bool hasCt() const
Get whether color temperature is stored.
Definition: Scene.cpp:65
Scene stored in the bridge.
Definition: Scene.h:115
XYBrightness getXY() const
Get xy color of the light.
Definition: Scene.cpp:59