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