Loading...
Searching...
No Matches
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.
| Rule (int id, const HueCommandAPI &commands, std::chrono::steady_clock::duration refreshDuration, const nlohmann::json &currentState)
| Creates rule with id.
void | refresh (bool force=false)
| Refreshes internal cached state.
void | setRefreshDuration (std::chrono::steady_clock::duration refreshDuration)
| Sets custom refresh interval for this rule.
int | getId () const
| Get rule identifier.
std::string | getName () const
| Get rule name.
void | setName (const std::string &name)
| Set rule name.
time::AbsoluteTime | getCreated () const
| Get created time.
time::AbsoluteTime | getLastTriggered () const
| Get time the rule was last triggered.
int | getTimesTriggered () const
| Get the number of times the rule was triggered.
bool | isEnabled () const
| Get whether rule is enabled or disabled.
void | setEnabled (bool enabled)
| Enable or disable rule.
std::string | getOwner () const
| Get user that created or last changed the rule.
std::vector< Condition > | getConditions () const
| Get the conditions that have to be met.
std::vector< Action > | getActions () const
| Get the actions that are executed.
void | setConditions (const std::vector< Condition > &conditions)
| Set conditions for the rule.
void | setActions (const std::vector< Action > &actions)
| Set actions for the rule.

## 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

  id | Rule id in the bridge
  baseCache | Cache 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

  id | Rule id in the bridge
  commands | HueCommandAPI for requests
  refreshDuration | Time between refreshing the cached state.
  currentState | The 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

  force | `true` 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_error | when system or socket operations fail
  HueException | when response contained no body
  HueAPIResponseException | when response contains an error
  nlohmann::json::parse_error | when response could not be parsed

## setActions()

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

Set actions for the rule.

Parameters

  actions | The 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

  conditions | All conditions that need to be fulfilled. Must not be empty.

Exceptions

  std::system_error | when system or socket operations fail
  HueException | when response contained no body
  HueAPIResponseException | when response contains an error
  nlohmann::json::parse_error | when response could not be parsed

## setEnabled()

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

Enable or disable rule.

Parameters

  enabled | whether the rule is triggered.

Exceptions

  std::system_error | when system or socket operations fail
  HueException | when response contained no body
  HueAPIResponseException | when response contains an error
  nlohmann::json::parse_error | when response could not be parsed

## setName()

void hueplusplus::Rule::setName | ( | const std::string & | name | ) |

Set rule name.

Parameters

  name | New name for the rule. Must be unique for all rules, otherwise a number is added.

Exceptions

  std::system_error | when system or socket operations fail
  HueException | when response contained no body
  HueAPIResponseException | when response contains an error
  nlohmann::json::parse_error | when response could not be parsed

## setRefreshDuration()

void hueplusplus::Rule::setRefreshDuration | ( | std::chrono::steady_clock::duration | refreshDuration | ) |

Sets custom refresh interval for this rule.

Parameters

  refreshDuration | The new minimum duration between refreshes. May be 0 or c_refreshNever.

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

- include/hueplusplus/Rule.h
- src/Rule.cpp