SinricPro Library
SinricProDimSwitch

Device which supports on / off and dimming commands. More...

Inheritance diagram for SinricProDimSwitch:
SinricProDevice SinricProFan

Public Types

typedef std::function< bool(const String &, int &)> SetPowerLevelCallback
 Definition for setPowerLevel callback. More...
 
typedef std::function< bool(const String &, int &)> AdjustPowerLevelCallback
 Definition for onAdjustPowerLevel callback. More...
 
typedef std::function< bool(const String &, bool &)> PowerStateCallback
 Callback definition for onPowerState function. 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...
 
virtual 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...
 

Detailed Description

Device which supports on / off and dimming commands.

Member Typedef Documentation

◆ AdjustPowerLevelCallback

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

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
}

◆ PowerStateCallback

typedef std::function<bool(const String&, bool&)> PowerStateCallback
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
}

◆ SetPowerLevelCallback

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

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
}

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

◆ onPowerState()

void onPowerState ( PowerStateCallback  cb)
virtualinherited

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

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
SinricProDimSwitch::onPowerLevel
void onPowerLevel(SetPowerLevelCallback cb)
Set callback function for setPowerLevel request.
Definition: SinricProDimSwitch.h:98
SinricProDimSwitch::onAdjustPowerLevel
void onAdjustPowerLevel(AdjustPowerLevelCallback cb)
Set callback function for adjustPowerLevel request.
Definition: SinricProDimSwitch.h:108
SinricProDevice::onPowerState
virtual void onPowerState(PowerStateCallback cb)
Set callback function for powerState request.
Definition: SinricProDevice.h:145