hueplusplus
1.0.0
|
Class for generic or unknown sensor types. More...
#include <hueplusplus/Sensor.h>
Public Member Functions | |
Sensor (int id, const std::shared_ptr< APICache > &baseCache) | |
Construct Sensor with shared cache. More... | |
Sensor (int id, const HueCommandAPI &commands, std::chrono::steady_clock::duration refreshDuration, const nlohmann::json ¤tState) | |
Construct Sensor. More... | |
time::AbsoluteTime | getLastUpdated () const |
Get time of last status update. More... | |
nlohmann::json | getState () const |
Get state object. More... | |
void | setStateAttribute (const std::string &key, const nlohmann::json &value) |
Set part of the sensor state. More... | |
std::string | getStateAddress (const std::string &key) const |
Get address of the given state attribute, used for conditions. More... | |
bool | isCertified () const |
Check if the sensor is Hue certified. More... | |
bool | isPrimary () const |
Check if the sensor is primary sensor of the device. More... | |
template<typename T > | |
T | asSensorType () const & |
Convert sensor to a specific type. More... | |
template<typename T > | |
T | asSensorType () && |
Convert sensor to a specific type. More... | |
Config attributes | |
bool | hasOn () const |
Check whether the sensor has an on attribute. More... | |
bool | isOn () const |
check whether the sensor is turned on More... | |
void | setOn (bool on) |
Turn sensor on or off. More... | |
bool | hasBatteryState () const |
Check whether the sensor has a battery state. More... | |
int | getBatteryState () const |
Get battery state. More... | |
void | setBatteryState (int percent) |
Set battery state. More... | |
bool | hasAlert () const |
Check whether the sensor has alerts. More... | |
Alert | getLastAlert () const |
Get last sent alert. More... | |
void | sendAlert (Alert type) |
Send alert. More... | |
bool | hasReachable () const |
Check whether the sensor has reachable validation. More... | |
bool | isReachable () const |
Get whether sensor is reachable. More... | |
bool | hasUserTest () const |
Check whether the sensor has a user test mode. More... | |
void | setUserTest (bool enabled) |
Enable or disable user test mode. More... | |
bool | hasURL () const |
Check whether the sensor has a URL. More... | |
std::string | getURL () const |
Get sensor URL. More... | |
void | setURL (const std::string &url) |
Set sensor URL. More... | |
std::vector< std::string > | getPendingConfig () const |
Get pending config entries, if they exist. More... | |
bool | hasLEDIndication () const |
Check whether the sensor has an LED indicator. More... | |
bool | getLEDIndication () const |
Get whether the indicator LED is on. More... | |
void | setLEDIndication (bool on) |
Turn LED indicator on or off. More... | |
nlohmann::json | getConfig () const |
Get entire config object. More... | |
void | setConfigAttribute (const std::string &key, const nlohmann::json &value) |
Set attribute in the sensor config. More... | |
Public Member Functions inherited from hueplusplus::BaseDevice | |
virtual | ~BaseDevice ()=default |
Virtual destructor. More... | |
virtual int | getId () const |
Const function that returns the id of this device. More... | |
virtual std::string | getType () const |
Const function that returns the device type. More... | |
virtual std::string | getName () |
Function that returns the name of the device. More... | |
virtual std::string | getName () const |
Const function that returns the name of the device. More... | |
virtual std::string | getModelId () const |
Const function that returns the modelid of the device. More... | |
virtual std::string | getUId () const |
Const function that returns the uniqueid of the device. More... | |
virtual std::string | getManufacturername () const |
Const function that returns the manufacturername of the device. More... | |
virtual std::string | getProductname () const |
Const function that returns the productname of the device. More... | |
virtual std::string | getSwVersion () |
Function that returns the software version of the device. More... | |
virtual std::string | getSwVersion () const |
Const function that returns the software version of the device. More... | |
virtual bool | setName (const std::string &name) |
Function that sets the name of the device. More... | |
virtual void | refresh (bool force=false) |
Refreshes internal cached state. More... | |
virtual void | setRefreshDuration (std::chrono::steady_clock::duration refreshDuration) |
Sets custom refresh interval for this device. More... | |
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. More... | |
BaseDevice (int id, const HueCommandAPI &commands, const std::string &path, std::chrono::steady_clock::duration refreshDuration, const nlohmann::json ¤tState) | |
Protected ctor that is used by subclasses. More... | |
virtual nlohmann::json | sendPutRequest (const std::string &subPath, const nlohmann::json &request, FileInfo fileInfo) |
Utility function to send a put request to the device. More... | |
Protected Attributes inherited from hueplusplus::BaseDevice | |
int | id |
holds the id of the device More... | |
APICache | state |
holds the current state of the device More... | |
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.
hueplusplus::Sensor::Sensor | ( | int | id, |
const std::shared_ptr< APICache > & | baseCache | ||
) |
Construct Sensor with shared cache.
id | Integer that specifies the id of this sensor |
baseCache | Cache of the SensorList. |
hueplusplus::Sensor::Sensor | ( | int | id, |
const HueCommandAPI & | commands, | ||
std::chrono::steady_clock::duration | refreshDuration, | ||
const nlohmann::json & | currentState | ||
) |
Construct Sensor.
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. |
|
inline |
Convert sensor to a specific type.
HueException | when sensor type does not match requested type |
|
inline |
Convert sensor to a specific type.
HueException | when sensor type does not match requested type |
Move construct T
to be more efficient when the type is wanted directly.
int hueplusplus::Sensor::getBatteryState | ( | ) | const |
Get battery state.
nlohmann::json::out_of_range | when sensor has no battery status. |
nlohmann::json hueplusplus::Sensor::getConfig | ( | ) | const |
Get entire config object.
Alert hueplusplus::Sensor::getLastAlert | ( | ) | const |
Get last sent alert.
nlohmann::json::out_of_range | when sensor has no alert. |
time::AbsoluteTime hueplusplus::Sensor::getLastUpdated | ( | ) | const |
Get time of last status update.
bool hueplusplus::Sensor::getLEDIndication | ( | ) | const |
Get whether the indicator LED is on.
nlohmann::json::out_of_range | when sensor has no LED |
std::vector< std::string > hueplusplus::Sensor::getPendingConfig | ( | ) | const |
Get pending config entries, if they exist.
Attempts to set pending config entries may cause errors.
nlohmann::json hueplusplus::Sensor::getState | ( | ) | const |
Get state object.
std::string hueplusplus::Sensor::getStateAddress | ( | const std::string & | key | ) | const |
Get address of the given state attribute, used for conditions.
key | Key in the state object |
key
prefixed with the path to the sensor state std::string hueplusplus::Sensor::getURL | ( | ) | const |
Get sensor URL.
Only CLIP sensors can have a URL.
bool hueplusplus::Sensor::hasAlert | ( | ) | const |
Check whether the sensor has alerts.
bool hueplusplus::Sensor::hasBatteryState | ( | ) | const |
Check whether the sensor has a battery state.
bool hueplusplus::Sensor::hasLEDIndication | ( | ) | const |
Check whether the sensor has an LED indicator.
bool hueplusplus::Sensor::hasOn | ( | ) | const |
Check whether the sensor has an on attribute.
bool hueplusplus::Sensor::hasReachable | ( | ) | const |
Check whether the sensor has reachable validation.
bool hueplusplus::Sensor::hasURL | ( | ) | const |
Check whether the sensor has a URL.
bool hueplusplus::Sensor::hasUserTest | ( | ) | const |
Check whether the sensor has a user test mode.
bool hueplusplus::Sensor::isCertified | ( | ) | const |
Check if the sensor is Hue certified.
bool hueplusplus::Sensor::isOn | ( | ) | const |
check whether the sensor is turned on
Sensors which are off do not change their status
nlohmann::json::out_of_range | when on attribute does not exist. |
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.
bool hueplusplus::Sensor::isReachable | ( | ) | const |
Get whether sensor is reachable.
nlohmann::json::out_of_range | when sensor has no reachable validation |
void hueplusplus::Sensor::sendAlert | ( | Alert | type | ) |
Send alert.
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 |
void hueplusplus::Sensor::setBatteryState | ( | int | percent | ) |
Set battery state.
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 |
void hueplusplus::Sensor::setConfigAttribute | ( | const std::string & | key, |
const nlohmann::json & | value | ||
) |
Set attribute in the sensor config.
key | Key of the config attribute |
value | Any value to set the attribute to |
Can be used to configure sensors with additional config entries.
void hueplusplus::Sensor::setLEDIndication | ( | bool | on | ) |
Turn LED indicator on or off.
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 |
void hueplusplus::Sensor::setOn | ( | bool | on | ) |
Turn sensor on or off.
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 |
void hueplusplus::Sensor::setStateAttribute | ( | const std::string & | key, |
const nlohmann::json & | value | ||
) |
Set part of the sensor state.
key | Key in the state object |
value | New value |
The state can usually only be set on CLIP sensors, not on physical devices.
void hueplusplus::Sensor::setURL | ( | const std::string & | url | ) |
Set sensor URL.
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 |
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.
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 |