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

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

#include <hueplusplus/Sensor.h>

+ Inheritance diagram for hueplusplus::Sensor:
+ Collaboration diagram for hueplusplus::Sensor:

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 &currentState)
 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 >
asSensorType () const &
 Convert sensor to a specific type. More...
 
template<typename 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 &currentState)
 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...
 

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
idInteger that specifies the id of this sensor
baseCacheCache 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
idInteger that specifies the id of this sensor
commandsHueCommandAPI for communication with the bridge
refreshDurationTime between refreshing the cached state.
currentStateThe current state, may be null.

Member Function Documentation

◆ asSensorType() [1/2]

template<typename T >
T hueplusplus::Sensor::asSensorType ( ) const &
inline

Convert sensor to a specific type.

Template Parameters
TSensor type to convert to (from Sensors)
Exceptions
HueExceptionwhen sensor type does not match requested type

◆ asSensorType() [2/2]

template<typename T >
T hueplusplus::Sensor::asSensorType ( ) &&
inline

Convert sensor to a specific type.

Template Parameters
TSensor type to convert to (from Sensors)
Exceptions
HueExceptionwhen sensor type does not match requested type

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

◆ getBatteryState()

int hueplusplus::Sensor::getBatteryState ( ) const

Get battery state.

Returns
Battery state in percent
Exceptions
nlohmann::json::out_of_rangewhen 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_rangewhen 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_rangewhen 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
keyKey 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_rangewhen 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_rangewhen sensor has no reachable validation

◆ sendAlert()

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

Send alert.

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

◆ setBatteryState()

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

Set battery 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

◆ setConfigAttribute()

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

Set attribute in the sensor config.

Parameters
keyKey of the config attribute
valueAny 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_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

◆ setOn()

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

Turn sensor on or off.

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

◆ setStateAttribute()

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

Set part of the sensor state.

Parameters
keyKey in the state object
valueNew 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_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

◆ 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_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: