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

Rule stored in the bridge. More...

#include <hueplusplus/Rule.h>

Public Member Functions

 Rule (int id, const std::shared_ptr< APICache > &baseCache)
 Creates rule with shared cache. More...
 
 Rule (int id, const HueCommandAPI &commands, std::chrono::steady_clock::duration refreshDuration, const nlohmann::json &currentState)
 Creates rule with id. 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 rule. More...
 
int getId () const
 Get rule identifier. More...
 
std::string getName () const
 Get rule name. More...
 
void setName (const std::string &name)
 Set rule name. More...
 
time::AbsoluteTime getCreated () const
 Get created time. More...
 
time::AbsoluteTime getLastTriggered () const
 Get time the rule was last triggered. More...
 
int getTimesTriggered () const
 Get the number of times the rule was triggered. More...
 
bool isEnabled () const
 Get whether rule is enabled or disabled. More...
 
void setEnabled (bool enabled)
 Enable or disable rule. More...
 
std::string getOwner () const
 Get user that created or last changed the rule. More...
 
std::vector< ConditiongetConditions () const
 Get the conditions that have to be met. More...
 
std::vector< ActiongetActions () const
 Get the actions that are executed. More...
 
void setConditions (const std::vector< Condition > &conditions)
 Set conditions for the rule. More...
 
void setActions (const std::vector< Action > &actions)
 Set actions for the rule. More...
 

Detailed Description

Rule stored in the bridge.

Rules are used to automatically trigger Actions when certain events happen. The bridge can only support a limited number of rules, conditions and actions.

They are deactivated if any errors occur when they are evaluated.

Constructor & Destructor Documentation

◆ Rule() [1/2]

hueplusplus::Rule::Rule ( int  id,
const std::shared_ptr< APICache > &  baseCache 
)

Creates rule with shared cache.

Parameters
idRule id in the bridge
baseCacheCache of the rule list.

◆ Rule() [2/2]

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

Creates rule with id.

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

Member Function Documentation

◆ getActions()

std::vector< Action > hueplusplus::Rule::getActions ( ) const

Get the actions that are executed.

At least one action must exist.

◆ getConditions()

std::vector< Condition > hueplusplus::Rule::getConditions ( ) const

Get the conditions that have to be met.

The rule triggers the actions when all conditions are true. At least one condition must exist.

◆ getCreated()

time::AbsoluteTime hueplusplus::Rule::getCreated ( ) const

Get created time.

◆ getId()

int hueplusplus::Rule::getId ( ) const

Get rule identifier.

◆ getLastTriggered()

time::AbsoluteTime hueplusplus::Rule::getLastTriggered ( ) const

Get time the rule was last triggered.

◆ getName()

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

Get rule name.

The rule name is always unique for the bridge.

◆ getOwner()

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

Get user that created or last changed the rule.

◆ getTimesTriggered()

int hueplusplus::Rule::getTimesTriggered ( ) const

Get the number of times the rule was triggered.

◆ isEnabled()

bool hueplusplus::Rule::isEnabled ( ) const

Get whether rule is enabled or disabled.

◆ refresh()

void hueplusplus::Rule::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

◆ setActions()

void hueplusplus::Rule::setActions ( const std::vector< Action > &  actions)

Set actions for the rule.

Parameters
actionsThe actions that are triggered when the conditions are met. Must not be empty.

◆ setConditions()

void hueplusplus::Rule::setConditions ( const std::vector< Condition > &  conditions)

Set conditions for the rule.

Parameters
conditionsAll conditions that need to be fulfilled. Must not be empty.
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

◆ setEnabled()

void hueplusplus::Rule::setEnabled ( bool  enabled)

Enable or disable rule.

Parameters
enabledwhether the rule is triggered.
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::Rule::setName ( const std::string &  name)

Set rule name.

Parameters
nameNew name for the rule. Must be unique for all rules, 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::Rule::setRefreshDuration ( std::chrono::steady_clock::duration  refreshDuration)

Sets custom refresh interval for this rule.

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

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