SinricPro Library
SinricProFan

Device to turn on / off a fan and change it's speed by using powerlevel. More...

Inheritance diagram for SinricProFan:

Public Types

using PowerStateCallback = std::function< bool(const String &, bool &)>
 Callback definition for onPowerState function. More...
 
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 onPowerState (PowerStateCallback cb)
 Set callback function for powerState request. More...
 
bool sendPowerStateEvent (bool state, String cause="PHYSICAL_INTERACTION")
 Send setPowerState event to SinricPro Server indicating actual power state. More...
 
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

Device to turn on / off a fan and change it's speed by using powerlevel.

Member Typedef Documentation

◆ AdjustPowerLevelCallback

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

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

◆ PowerStateCallback

using PowerStateCallback = std::function<bool(const String &, bool &)>
inherited

Callback definition for onPowerState function.

Gets called when device receive a setPowerState reuqest

Parameters
[in]deviceIdString which contains the ID of device
[in]statetrue = device is requested to turn on
false = device is requested to turn off
[out]statetrue = device has been turned on
false = device has been turned off
Returns
the success of the request
Return values
truerequest handled properly
falserequest was not handled properly because of some error

Example-Code

bool onPowerState(const String &deviceId, bool &state) {
Serial.printf("Device %s turned %s\r\n", deviceId.c_str(), state?"on":"off");
return true; // request handled properly
}
void onPowerState(PowerStateCallback cb)
Set callback function for powerState request.
Definition: PowerStateController.h:47

◆ SetPowerLevelCallback

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

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)
inherited

Set callback function for adjustPowerLevel request.

Parameters
cbFunction pointer to a AdjustPowerLevelCallback function
See also
AdjustPowerLevelCallback

◆ onPowerLevel()

void onPowerLevel ( SetPowerLevelCallback  cb)
inherited

Set callback function for setPowerLevel request.

Parameters
cbFunction pointer to a SetPowerLevelCallback function
See also
SetPowerLevelCallback

◆ onPowerState()

void onPowerState ( PowerStateCallback  cb)
inherited

Set callback function for powerState request.

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

◆ sendPowerLevelEvent()

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

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

◆ sendPowerStateEvent()

bool sendPowerStateEvent ( bool  state,
String  cause = "PHYSICAL_INTERACTION" 
)
inherited

Send setPowerState event to SinricPro Server indicating actual power state.

Parameters
statetrue = device turned on
false = device turned off
cause(optional) String reason why event is sent (default = "PHYSICAL_INTERACTION")
Returns
the success of sending the even
Return values
trueevent has been sent successfully
falseevent has not been sent, maybe you sent to much events in a short distance of time