hueplusplus  1.0.0
Public Types | Public Member Functions | List of all members
hueplusplus::Scene Class Reference

Scene stored in the bridge. More...

#include <hueplusplus/Scene.h>

Public Types

enum  Type { Type::lightScene, Type::groupScene }
 Type of the scen. More...
 

Public Member Functions

 Scene (const std::string &id, const std::shared_ptr< APICache > &baseCache)
 Creates scene with shared cache. More...
 
 Scene (const std::string &id, const HueCommandAPI &commands, std::chrono::steady_clock::duration refreshDuration, const nlohmann::json &currentState)
 Construct existing Scene. More...
 
void refresh (bool force=false)
 Refreshes internal cached state. More...
 
void setRefreshDuration (std::chrono::steady_clock::duration refreshDuration)
 Sets custom refresh interval for this group. More...
 
std::string getId () const
 Get scene identifier. More...
 
std::string getName () const
 Get scene name. More...
 
void setName (const std::string &name)
 Set scene name. More...
 
Type getType () const
 Get scene type. More...
 
int getGroupId () const
 Get group id for a GroupScene. More...
 
std::vector< int > getLightIds () const
 Get light ids. More...
 
void setLightIds (const std::vector< int > &ids)
 Set light ids for LightScene. More...
 
std::string getOwner () const
 Get user that created or last changed the scene. More...
 
bool getRecycle () const
 Get whether the scene can be automatically deleted. More...
 
bool isLocked () const
 Get whether scene is locked by a rule or schedule. More...
 
std::string getAppdata () const
 Get app specific data. More...
 
int getAppdataVersion () const
 Get version of app specific data. More...
 
void setAppdata (const std::string &data, int version)
 Set app specific data. More...
 
std::string getPicture () const
 Get picture, reserved for future use. More...
 
time::AbsoluteTime getLastUpdated () const
 Get time the scene was created/updated. More...
 
int getVersion () const
 Get version of the scene. More...
 
std::map< int, LightStategetLightStates () const
 Get stored states of the lights. More...
 
void setLightStates (const std::map< int, LightState > &states)
 Set light states. More...
 
void storeCurrentLightState ()
 Store current light state of every light in the scene. More...
 
void storeCurrentLightState (int transition)
 Store current light state and update transition time. More...
 
void recall ()
 Recall scene, putting every light in the stored state. More...
 

Detailed Description

Scene stored in the bridge.

Scenes bundle the state of multiple lights so it can be recalled later.

Member Enumeration Documentation

◆ Type

Type of the scen.

Enumerator
lightScene 

The scene affects specific lights.

groupScene 

The scene affects all light of a specific group.

Constructor & Destructor Documentation

◆ Scene() [1/2]

hueplusplus::Scene::Scene ( const std::string &  id,
const std::shared_ptr< APICache > &  baseCache 
)

Creates scene with shared cache.

Parameters
idScene id in the bridge
baseCacheCache of the scene list.

◆ Scene() [2/2]

hueplusplus::Scene::Scene ( const std::string &  id,
const HueCommandAPI commands,
std::chrono::steady_clock::duration  refreshDuration,
const nlohmann::json &  currentState 
)

Construct existing Scene.

Parameters
idScene id
commandsHueCommandAPI for requests
refreshDurationTime between refreshing the cached state
currentStateThe current state, may be null.

Member Function Documentation

◆ getAppdata()

std::string hueplusplus::Scene::getAppdata ( ) const

Get app specific data.

◆ getAppdataVersion()

int hueplusplus::Scene::getAppdataVersion ( ) const

Get version of app specific data.

◆ getGroupId()

int hueplusplus::Scene::getGroupId ( ) const

Get group id for a GroupScene.

Returns
Group id or 0 if the scene is a LightScene.

◆ getId()

std::string hueplusplus::Scene::getId ( ) const

Get scene identifier.

◆ getLastUpdated()

time::AbsoluteTime hueplusplus::Scene::getLastUpdated ( ) const

Get time the scene was created/updated.

◆ getLightIds()

std::vector< int > hueplusplus::Scene::getLightIds ( ) const

Get light ids.

For a GroupScene, the light ids are the lights in the group.

◆ getLightStates()

std::map< int, LightState > hueplusplus::Scene::getLightStates ( ) const

Get stored states of the lights.

Returns
LightStates for each light in the scene, or an empty map for legacy scenes.

◆ getName()

std::string hueplusplus::Scene::getName ( ) const

Get scene name.

The scene name is always unique for the bridge. It defaults to the id.

◆ getOwner()

std::string hueplusplus::Scene::getOwner ( ) const

Get user that created or last changed the scene.

◆ getPicture()

std::string hueplusplus::Scene::getPicture ( ) const

Get picture, reserved for future use.

Currently always an empty string.

◆ getRecycle()

bool hueplusplus::Scene::getRecycle ( ) const

Get whether the scene can be automatically deleted.

◆ getType()

Scene::Type hueplusplus::Scene::getType ( ) const

Get scene type.

GroupScenes are deleted when the group is deleted.

◆ getVersion()

int hueplusplus::Scene::getVersion ( ) const

Get version of the scene.

Returns
1 for legacy scene without lightstates
2 for updated scenes with lightstates

◆ isLocked()

bool hueplusplus::Scene::isLocked ( ) const

Get whether scene is locked by a rule or schedule.

◆ recall()

void hueplusplus::Scene::recall ( )

Recall scene, putting every light in the stored state.

Exceptions
std::system_errorwhen system or socket operations fail
HueExceptionwhen response contained no body
HueAPIResponseExceptionwhen response contains an error
nlohmann::json::parse_errorwhen response could not be parsed

◆ refresh()

void hueplusplus::Scene::refresh ( bool  force = false)

Refreshes internal cached state.

Parameters
forcetrue forces a refresh, regardless of how long the last refresh was ago. false to only refresh when enough time has passed (needed e.g. when calling only const methods).
Exceptions
std::system_errorwhen system or socket operations fail
HueExceptionwhen response contained no body
HueAPIResponseExceptionwhen response contains an error
nlohmann::json::parse_errorwhen response could not be parsed

◆ setAppdata()

void hueplusplus::Scene::setAppdata ( const std::string &  data,
int  version 
)

Set app specific data.

Parameters
dataCustom data in any format, max length 16.
versionVersion of the data
Exceptions
std::system_errorwhen system or socket operations fail
HueExceptionwhen response contained no body
HueAPIResponseExceptionwhen response contains an error
nlohmann::json::parse_errorwhen response could not be parsed

◆ setLightIds()

void hueplusplus::Scene::setLightIds ( const std::vector< int > &  ids)

Set light ids for LightScene.

Parameters
idsNew light ids

Light ids cannot be changed on GroupScene. Change the lights in the group instead.

Exceptions
std::system_errorwhen system or socket operations fail
HueExceptionwhen response contained no body
HueAPIResponseExceptionwhen response contains an error
nlohmann::json::parse_errorwhen response could not be parsed

◆ setLightStates()

void hueplusplus::Scene::setLightStates ( const std::map< int, LightState > &  states)

Set light states.

Parameters
statesNew states for each light in the scene. Should contain exactly the lights in the scene. Additional states might cause an error.
Exceptions
std::system_errorwhen system or socket operations fail
HueExceptionwhen response contained no body
HueAPIResponseExceptionwhen response contains an error
nlohmann::json::parse_errorwhen response could not be parsed

◆ setName()

void hueplusplus::Scene::setName ( const std::string &  name)

Set scene name.

Parameters
nameNew name for the scene. Must be unique for all schedules, otherwise a number is added.
Exceptions
std::system_errorwhen system or socket operations fail
HueExceptionwhen response contained no body
HueAPIResponseExceptionwhen response contains an error
nlohmann::json::parse_errorwhen response could not be parsed

◆ setRefreshDuration()

void hueplusplus::Scene::setRefreshDuration ( std::chrono::steady_clock::duration  refreshDuration)

Sets custom refresh interval for this group.

Parameters
refreshDurationThe new minimum duration between refreshes. May be 0 or c_refreshNever.

◆ storeCurrentLightState() [1/2]

void hueplusplus::Scene::storeCurrentLightState ( )

Store current light state of every light in the scene.

Exceptions
std::system_errorwhen system or socket operations fail
HueExceptionwhen response contained no body
HueAPIResponseExceptionwhen response contains an error
nlohmann::json::parse_errorwhen response could not be parsed

◆ storeCurrentLightState() [2/2]

void hueplusplus::Scene::storeCurrentLightState ( int  transition)

Store current light state and update transition time.

Parameters
transitionThe updated transition time to this scene
Exceptions
std::system_errorwhen system or socket operations fail
HueExceptionwhen response contained no body
HueAPIResponseExceptionwhen response contains an error
nlohmann::json::parse_errorwhen response could not be parsed

The documentation for this class was generated from the following files: