Loading...
Searching...
No Matches
hueplusplus::Sensor Class Reference

Class for generic or unknown sensor types. More...

`#include <hueplusplus/Sensor.h>`

Inheritance diagram for hueplusplus::Sensor:
[legend]
Collaboration diagram for hueplusplus::Sensor:
[legend]

## Public Member Functions

| Sensor (int id, const std::shared_ptr< APICache > &baseCache)
| Construct Sensor with shared cache.
| Sensor (int id, const HueCommandAPI &commands, std::chrono::steady_clock::duration refreshDuration, const nlohmann::json &currentState)
| Construct Sensor.
time::AbsoluteTime | getLastUpdated () const
| Get time of last status update.
nlohmann::json | getState () const
| Get state object.
void | setStateAttribute (const std::string &key, const nlohmann::json &value)
| Set part of the sensor state.
std::string | getStateAddress (const std::string &key) const
| Get address of the given state attribute, used for conditions.
bool | isCertified () const
| Check if the sensor is Hue certified.
bool | isPrimary () const
| Check if the sensor is primary sensor of the device.
template<typename T >
T | asSensorType () const &
| Convert sensor to a specific type.
template<typename T >
T | asSensorType () &&
| Convert sensor to a specific type.
Config attributes
bool | hasOn () const
| Check whether the sensor has an on attribute.
bool | isOn () const
| check whether the sensor is turned on
void | setOn (bool on)
| Turn sensor on or off.
bool | hasBatteryState () const
| Check whether the sensor has a battery state.
int | getBatteryState () const
| Get battery state.
void | setBatteryState (int percent)
| Set battery state.
bool | hasAlert () const
| Check whether the sensor has alerts.
Alert | getLastAlert () const
| Get last sent alert.
void | sendAlert (Alert type)
| Send alert.
bool | hasReachable () const
| Check whether the sensor has reachable validation.
bool | isReachable () const
| Get whether sensor is reachable.
bool | hasUserTest () const
| Check whether the sensor has a user test mode.
void | setUserTest (bool enabled)
| Enable or disable user test mode.
bool | hasURL () const
| Check whether the sensor has a URL.
std::string | getURL () const
| Get sensor URL.
void | setURL (const std::string &url)
| Set sensor URL.
std::vector< std::string > | getPendingConfig () const
| Get pending config entries, if they exist.
bool | hasLEDIndication () const
| Check whether the sensor has an LED indicator.
bool | getLEDIndication () const
| Get whether the indicator LED is on.
void | setLEDIndication (bool on)
| Turn LED indicator on or off.
nlohmann::json | getConfig () const
| Get entire config object.
void | setConfigAttribute (const std::string &key, const nlohmann::json &value)
| Set attribute in the sensor config.
Public Member Functions inherited from hueplusplus::BaseDevice
virtual | ~BaseDevice ()=default
| Virtual destructor.
virtual int | getId () const
| Const function that returns the id of this device.
virtual std::string | getType () const
| Const function that returns the device type.
virtual std::string | getName ()
| Function that returns the name of the device.
virtual std::string | getName () const
| Const function that returns the name of the device.
virtual std::string | getModelId () const
| Const function that returns the modelid of the device.
virtual std::string | getUId () const
| Const function that returns the uniqueid of the device.
virtual std::string | getManufacturername () const
| Const function that returns the manufacturername of the device.
virtual std::string | getProductname () const
| Const function that returns the productname of the device.
virtual std::string | getSwVersion ()
| Function that returns the software version of the device.
virtual std::string | getSwVersion () const
| Const function that returns the software version of the device.
virtual bool | setName (const std::string &name)
| Function that sets the name of the device.
virtual void | refresh (bool force=false)
| Refreshes internal cached state.
virtual void | setRefreshDuration (std::chrono::steady_clock::duration refreshDuration)
| Sets custom refresh interval for this device.

## Additional Inherited Members

Protected Member Functions inherited from hueplusplus::BaseDevice
| BaseDevice (int id, const std::shared_ptr< APICache > &baseCache)
| Protected ctor that is used by subclasses, construct with shared cache.
| BaseDevice (int id, const HueCommandAPI &commands, const std::string &path, std::chrono::steady_clock::duration refreshDuration, const nlohmann::json &currentState)
| Protected ctor that is used by subclasses.
virtual nlohmann::json | sendPutRequest (const std::string &subPath, const nlohmann::json &request, FileInfo fileInfo)
| Utility function to send a put request to the device.
Protected Attributes inherited from hueplusplus::BaseDevice
int | id
| holds the id of the device
APICache | state
| holds the current state of the device

## Detailed Description

Class for generic or unknown sensor types.

It is recommended to instead use the classes for specific types in Sensors. This class should only be used if the type cannot be known or is not supported.

## Constructor & Destructor Documentation

## Sensor() [1/2]

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

Construct Sensor with shared cache.

Parameters

  id | Integer that specifies the id of this sensor
  baseCache | Cache of the SensorList.

## Sensor() [2/2]

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

Construct Sensor.

Parameters

  id | Integer that specifies the id of this sensor
  commands | HueCommandAPI for communication with the bridge
  refreshDuration | Time between refreshing the cached state.
  currentState | The current state, may be null.

## Member Function Documentation

## asSensorType() [1/2]

template<typename T >

T hueplusplus::Sensor::asSensorType | ( |  | ) | &&

inline

Convert sensor to a specific type.

Template Parameters

  T | Sensor type to convert to (from Sensors)

Exceptions

  HueException | when sensor type does not match requested type

Move construct `T` to be more efficient when the type is wanted directly.

## asSensorType() [2/2]

template<typename T >

T hueplusplus::Sensor::asSensorType | ( |  | ) | const &

inline

Convert sensor to a specific type.

Template Parameters

  T | Sensor type to convert to (from Sensors)

Exceptions

  HueException | when sensor type does not match requested type

## getBatteryState()

int hueplusplus::Sensor::getBatteryState | ( |  | ) | const

Get battery state.

Returns
  Battery state in percent

Exceptions

  nlohmann::json::out_of_range | when sensor has no battery status.

## getConfig()

nlohmann::json hueplusplus::Sensor::getConfig | ( |  | ) | const

Get entire config object.

Returns
  A json object with the sensor configuration.

## getLastAlert()

Alert hueplusplus::Sensor::getLastAlert | ( |  | ) | const

Get last sent alert.

Note
  This is not cleared when the alert ends.

Exceptions

  nlohmann::json::out_of_range | when sensor has no alert.

## getLastUpdated()

time::AbsoluteTime hueplusplus::Sensor::getLastUpdated | ( |  | ) | const

Get time of last status update.

Returns
  The last update time, or a time with a zero duration from epoch if the last update time is not set.

## getLEDIndication()

bool hueplusplus::Sensor::getLEDIndication | ( |  | ) | const

Get whether the indicator LED is on.

Exceptions

  nlohmann::json::out_of_range | when sensor has no LED

## getPendingConfig()

std::vector< std::string > hueplusplus::Sensor::getPendingConfig | ( |  | ) | const

Get pending config entries, if they exist.

Returns
  The keys of config entries which have been modified, but were not committed to the device.

Attempts to set pending config entries may cause errors.

## getState()

nlohmann::json hueplusplus::Sensor::getState | ( |  | ) | const

Get state object.

## getStateAddress()

std::string hueplusplus::Sensor::getStateAddress | ( | const std::string & | key | ) | const

Get address of the given state attribute, used for conditions.

Parameters

  key | Key in the state object

Returns
  `key` prefixed with the path to the sensor state

## getURL()

std::string hueplusplus::Sensor::getURL | ( |  | ) | const

Get sensor URL.

Only CLIP sensors can have a URL.

## hasAlert()

bool hueplusplus::Sensor::hasAlert | ( |  | ) | const

Check whether the sensor has alerts.

## hasBatteryState()

bool hueplusplus::Sensor::hasBatteryState | ( |  | ) | const

Check whether the sensor has a battery state.

## hasLEDIndication()

bool hueplusplus::Sensor::hasLEDIndication | ( |  | ) | const

Check whether the sensor has an LED indicator.

## hasOn()

bool hueplusplus::Sensor::hasOn | ( |  | ) | const

Check whether the sensor has an on attribute.

## hasReachable()

bool hueplusplus::Sensor::hasReachable | ( |  | ) | const

Check whether the sensor has reachable validation.

## hasURL()

bool hueplusplus::Sensor::hasURL | ( |  | ) | const

Check whether the sensor has a URL.

## hasUserTest()

bool hueplusplus::Sensor::hasUserTest | ( |  | ) | const

Check whether the sensor has a user test mode.

## isCertified()

bool hueplusplus::Sensor::isCertified | ( |  | ) | const

Check if the sensor is Hue certified.

## isOn()

bool hueplusplus::Sensor::isOn | ( |  | ) | const

check whether the sensor is turned on

Sensors which are off do not change their status

Exceptions

  nlohmann::json::out_of_range | when on attribute does not exist.

## isPrimary()

bool hueplusplus::Sensor::isPrimary | ( |  | ) | const

Check if the sensor is primary sensor of the device.

When there are multiple sensors on one physical device (same MAC address), the primary device is used for the device information.

## isReachable()

bool hueplusplus::Sensor::isReachable | ( |  | ) | const

Get whether sensor is reachable.

Exceptions

  nlohmann::json::out_of_range | when sensor has no reachable validation

## sendAlert()

void hueplusplus::Sensor::sendAlert | ( | Alert | type | ) |

Send alert.

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

## setBatteryState()

void hueplusplus::Sensor::setBatteryState | ( | int | percent | ) |

Set battery state.

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

## setConfigAttribute()

void hueplusplus::Sensor::setConfigAttribute | ( | const std::string & | key,
|  | const nlohmann::json & | value
| ) |  |

Set attribute in the sensor config.

Parameters

  key | Key of the config attribute
  value | Any value to set the attribute to

Can be used to configure sensors with additional config entries.

## setLEDIndication()

void hueplusplus::Sensor::setLEDIndication | ( | bool | on | ) |

Turn LED indicator on or off.

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

## setOn()

void hueplusplus::Sensor::setOn | ( | bool | on | ) |

Turn sensor on or off.

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

## setStateAttribute()

void hueplusplus::Sensor::setStateAttribute | ( | const std::string & | key,
|  | const nlohmann::json & | value
| ) |  |

Set part of the sensor state.

Parameters

  key | Key in the state object
  value | New value

The state can usually only be set on CLIP sensors, not on physical devices.

## setURL()

void hueplusplus::Sensor::setURL | ( | const std::string & | url | ) |

Set sensor URL.

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

## setUserTest()

void hueplusplus::Sensor::setUserTest | ( | bool | enabled | ) |

Enable or disable user test mode.

In user test mode, changes are reported more frequently.# It remains on for 120 seconds or until turned off.

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

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

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