hueplusplus  1.0.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
hueplusplus::BaseDevice Class Reference

Base class for physical devices connected to the bridge (sensor or light). More...

#include <hueplusplus/BaseDevice.h>

+ Inheritance diagram for hueplusplus::BaseDevice:
+ Collaboration diagram for hueplusplus::BaseDevice:

Public Member Functions

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

Protected Member Functions

 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

int id
 holds the id of the device More...
 
APICache state
 holds the current state of the device More...
 

Detailed Description

Base class for physical devices connected to the bridge (sensor or light).

Constructor & Destructor Documentation

◆ ~BaseDevice()

virtual hueplusplus::BaseDevice::~BaseDevice ( )
virtualdefault

Virtual destructor.

◆ BaseDevice() [1/2]

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

Protected ctor that is used by subclasses, construct with shared cache.

Parameters
idInteger that specifies the id of this device
baseCacheCache of the ResourceList containing this device (must not be null).

◆ BaseDevice() [2/2]

hueplusplus::BaseDevice::BaseDevice ( int  id,
const HueCommandAPI commands,
const std::string &  path,
std::chrono::steady_clock::duration  refreshDuration,
const nlohmann::json &  currentState 
)
protected

Protected ctor that is used by subclasses.

Parameters
idInteger that specifies the id of this device
commandsHueCommandAPI for communication with the bridge
pathBase path for the resource type, ending with a '/'. Example: "/lights/"
refreshDurationTime between refreshing the cached state.
currentStateCurrent state of the device, may be null.

Member Function Documentation

◆ getId()

int hueplusplus::BaseDevice::getId ( ) const
virtual

Const function that returns the id of this device.

Returns
integer representing the device id

◆ getManufacturername()

std::string hueplusplus::BaseDevice::getManufacturername ( ) const
virtual

Const function that returns the manufacturername of the device.

Note
Only working on bridges with versions starting at 1.7
Returns
String containing the manufacturername or an empty string when the function is not supported

◆ getModelId()

std::string hueplusplus::BaseDevice::getModelId ( ) const
virtual

Const function that returns the modelid of the device.

Returns
String containing the modelid

◆ getName() [1/2]

std::string hueplusplus::BaseDevice::getName ( )
virtual

Function that returns the name of the device.

Returns
String containig the name of the device
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

◆ getName() [2/2]

std::string hueplusplus::BaseDevice::getName ( ) const
virtual

Const function that returns the name of the device.

Note
This will not refresh the device state
Returns
String containig the name of the thing

◆ getProductname()

std::string hueplusplus::BaseDevice::getProductname ( ) const
virtual

Const function that returns the productname of the device.

Note
Only working on bridges with versions starting at 1.24
Returns
String containing the productname or an empty string when the function is not supported

◆ getSwVersion() [1/2]

std::string hueplusplus::BaseDevice::getSwVersion ( )
virtual

Function that returns the software version of the device.

Returns
String containing the software version
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

◆ getSwVersion() [2/2]

std::string hueplusplus::BaseDevice::getSwVersion ( ) const
virtual

Const function that returns the software version of the device.

Note
This will not refresh the device state
Returns
String containing the software version

◆ getType()

std::string hueplusplus::BaseDevice::getType ( ) const
virtual

Const function that returns the device type.

Returns
String containing the type

◆ getUId()

std::string hueplusplus::BaseDevice::getUId ( ) const
virtual

Const function that returns the uniqueid of the device.

Note
Only working on bridges with versions starting at 1.4
Returns
String containing the uniqueid or an empty string when the function is not supported

◆ refresh()

void hueplusplus::BaseDevice::refresh ( bool  force = false)
virtual

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

◆ sendPutRequest()

nlohmann::json hueplusplus::BaseDevice::sendPutRequest ( const std::string &  subPath,
const nlohmann::json &  request,
FileInfo  fileInfo 
)
protectedvirtual

Utility function to send a put request to the device.

Parameters
subPathA path that is appended to the uri, note it should always start with a slash ("/")
requestA nlohmann::json aka the request to send
fileInfoFileInfo from calling function for exception details.
Returns
The parsed reply
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()

bool hueplusplus::BaseDevice::setName ( const std::string &  name)
virtual

Function that sets the name of the device.

Returns
Bool that is true on success
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::BaseDevice::setRefreshDuration ( std::chrono::steady_clock::duration  refreshDuration)
virtual

Sets custom refresh interval for this device.

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

Member Data Documentation

◆ id

int hueplusplus::BaseDevice::id
protected

holds the id of the device

◆ state

APICache hueplusplus::BaseDevice::state
protected

holds the current state of the device


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