SinricPro Library
PercentageController< T >

PercentageController. More...

Public Types

using SetPercentageCallback = std::function< bool(const String &, int &)>
 Callback definition for onSetPercentage function. More...
 
using AdjustPercentageCallback = std::function< bool(const String &, int &)>
 Callback definition for onAdjustPercentage function. More...
 

Public Member Functions

void onSetPercentage (SetPercentageCallback cb)
 Set callback function for setPercentage request. More...
 
void onAdjustPercentage (AdjustPercentageCallback cb)
 Set callback function for adjustPercentage request. More...
 
bool sendSetPercentageEvent (int percentage, String cause="PHYSICAL_INTERACTION")
 Send setPercentage event to SinricPro Server indicating actual percentage has changed. More...
 

Detailed Description

template<typename T>
class PercentageController< T >

PercentageController.

Member Typedef Documentation

◆ AdjustPercentageCallback

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

Callback definition for onAdjustPercentage function.

Gets called when device receive a adjustPercentage request

Parameters
[in]deviceIdString which contains the ID of device
[in]percentageDeltaInteger with relative percentage the device should change about (-100..100)
[out]percentageDeltaInteger with absolute percentage device has 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

int absolutePercentage;
bool onAdjustPercentage(const String &deviceId, int &percentageDelta) {
absolutePercentage += percentageDelta; // calculate absolute percentage
Serial.printf("Device %s percentage changed about %i to %d\r\n", deviceId.c_str(), percentageDelta, absolutePercentage);
percentageDelta = absolutePercentage; // return absolute percentage
return true; // request handled properly
}
void onAdjustPercentage(AdjustPercentageCallback cb)
Set callback function for adjustPercentage request.
Definition: PercentageController.h:77

◆ SetPercentageCallback

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

Callback definition for onSetPercentage function.

Gets called when device receive a setPercentage request

Parameters
[in]deviceIdString which contains the ID of device
[in]percentageInteger with percentage device should set to
[out]percentageInteger with percentage device has 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 onSetPercentage(const String &deviceId, int &percentage) {
Serial.printf("Device %s percentage %d\r\n", deviceId.c_str(), percentage);
return true; // request handled properly
}
void onSetPercentage(SetPercentageCallback cb)
Set callback function for setPercentage request.
Definition: PercentageController.h:67

Member Function Documentation

◆ onAdjustPercentage()

void onAdjustPercentage ( AdjustPercentageCallback  cb)

Set callback function for adjustPercentage request.

Parameters
cbFunction pointer to a AdjustPercentageCallback function
Returns
void
See also
AdjustPercentageCallback

◆ onSetPercentage()

void onSetPercentage ( SetPercentageCallback  cb)

Set callback function for setPercentage request.

Parameters
cbFunction pointer to a SetPercentageCallback function
Returns
void
See also
SetPercentageCallback

◆ sendSetPercentageEvent()

bool sendSetPercentageEvent ( int  percentage,
String  cause = "PHYSICAL_INTERACTION" 
)

Send setPercentage event to SinricPro Server indicating actual percentage has changed.

Parameters
percentageInteger reporting the percentage 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