hueplusplus 1.2.0
Loading...
Searching...
No Matches
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 <nlohmann/json.hpp>
30
31#include "APICache.h"
32#include "ColorUnits.h"
33#include "TimePattern.h"
34
35namespace hueplusplus
36{
39{
40public:
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;
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
90private:
91 nlohmann::json state;
92};
93
96{
97public:
98 LightStateBuilder& setOn(bool on);
99 LightStateBuilder& setBrightness(int brightness);
101 LightStateBuilder& setXY(const XY& xy);
102 LightStateBuilder& setCt(int mired);
103 LightStateBuilder& setColorloop(bool enabled);
105
107
108private:
109 nlohmann::json state;
110};
111
115class Scene
116{
117public:
119 enum class Type
120 {
121 lightScene,
123 };
124
125public:
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;
216 int getVersion() const;
217
220 std::map<int, LightState> getLightStates() const;
228 void setLightStates(const std::map<int, LightState>& states);
229
242 void storeCurrentLightState(int transition);
243
249 void recall();
250
251private:
257 void sendPutRequest(const std::string& path, const nlohmann::json& request, FileInfo fileInfo);
258
259private:
260 std::string id;
261 APICache state;
262};
263
268{
269public:
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
300private:
301 nlohmann::json request;
302};
303} // namespace hueplusplus
304
305#endif
Caches API GET requests and refreshes regularly.
Definition APICache.h:38
Parameters for creating a new Scene.
Definition Scene.h:268
CreateScene & setLightStates(const std::map< int, LightState > &states)
Set light states of the scene.
Definition Scene.cpp:382
CreateScene & setName(const std::string &name)
Set name.
Definition Scene.cpp:337
CreateScene & setLightIds(const std::vector< int > &ids)
Set light ids, making the scene a LightScene.
Definition Scene.cpp:354
CreateScene & setGroupId(int id)
Set group id, making the scene a GroupScene.
Definition Scene.cpp:343
nlohmann::json getRequest() const
Get request to create the scene.
Definition Scene.cpp:393
CreateScene & setRecycle(bool recycle)
Set whether the scene can be automatically deleted.
Definition Scene.cpp:370
CreateScene & setAppdata(const std::string &data, int version)
Set app specific data.
Definition Scene.cpp:376
Definition HueCommandAPI.h:38
Builder to create LightState.
Definition Scene.h:96
LightStateBuilder & setXY(const XY &xy)
Definition Scene.cpp:124
LightStateBuilder & setHueSat(const HueSaturation &hueSat)
Definition Scene.cpp:117
LightStateBuilder & setOn(bool on)
Definition Scene.cpp:105
LightState create()
Definition Scene.cpp:148
LightStateBuilder & setTransitionTime(int time)
Definition Scene.cpp:142
LightStateBuilder & setBrightness(int brightness)
Definition Scene.cpp:111
LightStateBuilder & setCt(int mired)
Definition Scene.cpp:130
LightStateBuilder & setColorloop(bool enabled)
Definition Scene.cpp:136
Immutable state of a light.
Definition Scene.h:39
int getTransitionTime() const
Get transition time to this light state.
Definition Scene.cpp:85
bool isOn() const
Get whether the light is on.
Definition Scene.cpp:29
bool hasEffect() const
Get whether effect is stored.
Definition Scene.cpp:75
bool hasHueSat() const
Get whether hue and saturation is stored.
Definition Scene.cpp:44
bool operator!=(const LightState &other) const
Inequality comparison.
Definition Scene.cpp:100
int getCt() const
Get color temperature of the light.
Definition Scene.cpp:70
bool hasBrightness() const
Get whether a brightness is stored.
Definition Scene.cpp:34
nlohmann::json toJson() const
Convert to json representation.
Definition Scene.cpp:90
XYBrightness getXY() const
Get xy color of the light.
Definition Scene.cpp:59
bool hasCt() const
Get whether color temperature is stored.
Definition Scene.cpp:65
bool operator==(const LightState &other) const
Equality comparison.
Definition Scene.cpp:95
bool getColorloop() const
Get whether colorloop effect is active.
Definition Scene.cpp:80
int getBrightness() const
Get brightness of the light.
Definition Scene.cpp:39
bool hasXY() const
Get whether xy color is stored.
Definition Scene.cpp:54
HueSaturation getHueSat() const
Get hue and saturation of the light.
Definition Scene.cpp:49
Scene stored in the bridge.
Definition Scene.h:116
bool getRecycle() const
Get whether the scene can be automatically deleted.
Definition Scene.cpp:242
Type getType() const
Get scene type.
Definition Scene.cpp:197
void setLightStates(const std::map< int, LightState > &states)
Set light states.
Definition Scene.cpp:298
time::AbsoluteTime getLastUpdated() const
Get time the scene was created/updated.
Definition Scene.cpp:273
Type
Type of the scen.
Definition Scene.h:120
@ lightScene
The scene affects specific lights.
@ groupScene
The scene affects all light of a specific group.
std::string getId() const
Get scene identifier.
Definition Scene.cpp:181
void setName(const std::string &name)
Set scene name.
Definition Scene.cpp:191
int getVersion() const
Get version of the scene.
Definition Scene.cpp:278
void setAppdata(const std::string &data, int version)
Set app specific data.
Definition Scene.cpp:262
void setRefreshDuration(std::chrono::steady_clock::duration refreshDuration)
Sets custom refresh interval for this group.
Definition Scene.cpp:176
void setLightIds(const std::vector< int > &ids)
Set light ids for LightScene.
Definition Scene.cpp:226
std::vector< int > getLightIds() const
Get light ids.
Definition Scene.cpp:216
std::string getName() const
Get scene name.
Definition Scene.cpp:186
std::string getPicture() const
Get picture, reserved for future use.
Definition Scene.cpp:268
void storeCurrentLightState()
Store current light state of every light in the scene.
Definition Scene.cpp:309
int getAppdataVersion() const
Get version of app specific data.
Definition Scene.cpp:257
void recall()
Recall scene, putting every light in the stored state.
Definition Scene.cpp:321
std::map< int, LightState > getLightStates() const
Get stored states of the lights.
Definition Scene.cpp:283
std::string getAppdata() const
Get app specific data.
Definition Scene.cpp:252
std::string getOwner() const
Get user that created or last changed the scene.
Definition Scene.cpp:237
void refresh(bool force=false)
Refreshes internal cached state.
Definition Scene.cpp:164
int getGroupId() const
Get group id for a GroupScene.
Definition Scene.cpp:211
bool isLocked() const
Get whether scene is locked by a rule or schedule.
Definition Scene.cpp:247
One-time, absolute time point.
Definition TimePattern.h:73
Namespace for the hueplusplus library.
Definition Action.h:28
Contains information about error location, use CURRENT_FILE_INFO to create.
Definition HueException.h:35
Color in hue and saturation.
Definition ColorUnits.h:32
Color and brightness in CIE.
Definition ColorUnits.h:63
Color in CIE x and y coordinates.
Definition ColorUnits.h:48