SinricPro Library
PowerLevelController< T >

PowerLevelController. More...

Inheritance diagram for PowerLevelController< T >:

Public Types

using SetPowerLevelCallback = std::function< bool(const String &, int &)>
 Definition for setPowerLevel callback. More...
 
using AdjustPowerLevelCallback = std::function< bool(const String &, int &)>
 Definition for onAdjustPowerLevel callback. More...
 

Public Member Functions

void onPowerLevel (SetPowerLevelCallback cb)
 Set callback function for setPowerLevel request. More...
 
void onAdjustPowerLevel (AdjustPowerLevelCallback cb)
 Set callback function for adjustPowerLevel request. More...
 
bool sendPowerLevelEvent (int powerLevel, String cause="PHYSICAL_INTERACTION")
 Send setPowerLevel event to SinricPro Server indicating actual power level. More...
 

Detailed Description

template<typename T>
class PowerLevelController< T >

PowerLevelController.

Member Typedef Documentation

◆ AdjustPowerLevelCallback

using AdjustPowerLevelCallback = std::function<bool(const String &, int &)>

Definition for onAdjustPowerLevel callback.

Gets called when device receive a adjustPowerLevel reuqest

Parameters
[in]deviceIdString which contains the ID of device
[in]powerLevelinteger -100..100 delta value which power level have to be changed
[out]powerLevelinteger 0..100 report the absolute powerlevel that the device have been set to
Returns
the success of the request
Return values
truerequest handled properly
falserequest can`t be handled properly because of some error

Example-Code

int absolutePowerLevel;
bool onAdjustPowerLevel(const String &deviceId, int &powerDelta) {
absolutePowerLevel += powerDelta; // calculate absolute power level
Serial.printf("Device %s brightness changed about %i to %d\r\n", deviceId.c_str(), powerDelta, absolutePowerLevel);
powerDelta = absolutePowerLevel; // return absolute power level
return true; // request handled properly
}
void onAdjustPowerLevel(AdjustPowerLevelCallback cb)
Set callback function for adjustPowerLevel request.
Definition: PowerLevelController.h:76

◆ SetPowerLevelCallback

using SetPowerLevelCallback = std::function<bool(const String &, int &)>

Definition for setPowerLevel callback.

Gets called when device receive a setPowerLevel reuqest

Parameters
[in]deviceIdString which contains the ID of device
[in]powerLevelinteger 0..100 new powerlevel the device should be set to
[out]powerLevelinteger 0..100 report the powerlevel that the device have been set to
Returns
the success of the request
Return values
truerequest handled properly
falserequest was not handled properly because of some error

Example-Code

bool onPowerLevel(const String &deviceId, int &powerLevel) {
Serial.printf("Device %s powerlevel %d\r\n", deviceId.c_str(), powerLevel);
return true; // request handled properly
}
void onPowerLevel(SetPowerLevelCallback cb)
Set callback function for setPowerLevel request.
Definition: PowerLevelController.h:65

Member Function Documentation

◆ onAdjustPowerLevel()

void onAdjustPowerLevel ( AdjustPowerLevelCallback  cb)

Set callback function for adjustPowerLevel request.

Parameters
cbFunction pointer to a AdjustPowerLevelCallback function
See also
AdjustPowerLevelCallback

◆ onPowerLevel()

void onPowerLevel ( SetPowerLevelCallback  cb)

Set callback function for setPowerLevel request.

Parameters
cbFunction pointer to a SetPowerLevelCallback function
See also
SetPowerLevelCallback

◆ sendPowerLevelEvent()

bool sendPowerLevelEvent ( int  powerLevel,
String  cause = "PHYSICAL_INTERACTION" 
)

Send setPowerLevel event to SinricPro Server indicating actual power level.

Parameters
powerLevelinteger 0..100 report the powerlevel that the device have been set to
cause(optional) Reason why event is sent (default = "PHYSICAL_INTERACTION")
Returns
the success of sending the event
Return values
trueevent has been sent successfully
falseevent has not been sent, maybe you sent to much events in a short distance of time