SinricPro Library
SinricProFanUS

Device to control a fan with on / off commands and its speed by a range value. More...

Inheritance diagram for SinricProFanUS:

Public Types

using PowerStateCallback = std::function< bool(const String &, bool &)>
 Callback definition for onPowerState function. More...
 
using SetRangeValueCallback = std::function< bool(const String &, int &)>
 Callback definition for onRangeValue function. More...
 
using GenericSetRangeValueCallback = std::function< bool(const String &, const String &, int &)>
 Callback definition for onRangeValue function on a specific instance. More...
 
using AdjustRangeValueCallback = std::function< bool(const String &, int &)>
 Callback definition for onAdjustRangeValue function. More...
 
using GenericAdjustRangeValueCallback = std::function< bool(const String &, const String &, int &)>
 Callback definition for onAdjustRangeValue function on a specific instance for custom devices. 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 onRangeValue (SetRangeValueCallback cb)
 Set callback function for setRangeValue request. More...
 
void onRangeValue (const String &instance, GenericSetRangeValueCallback cb)
 Set callback function for setRangeValue request on a specific instance (custom device) More...
 
void onAdjustRangeValue (AdjustRangeValueCallback cb)
 Set callback function for adjustRangeValue request. More...
 
bool sendRangeValueEvent (int rangeValue, String cause="PHYSICAL_INTERACTION")
 Send rangeValue event to report curent rangeValue to SinricPro server. More...
 
bool sendRangeValueEvent (const String &instance, int rangeValue, String cause="PHYSICAL_INTERACTION")
 Send rangeValue event to report curent rangeValue to SinricPro server for a specific instance (custom device) More...
 

Detailed Description

Device to control a fan with on / off commands and its speed by a range value.

Member Typedef Documentation

◆ AdjustRangeValueCallback

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

Callback definition for onAdjustRangeValue function.

Gets called when device receive a adjustRangeValue reuqest

Parameters
[in]deviceIdString which contains the ID of device
[in]rangeValueInteger -3..3 delta value for range value have to change
[out]rangeValueInteger 3..3 returning the absolute range value
Returns
the success of the request
Return values
truerequest handled properly
falserequest was not handled properly because of some error

Example-Code

int globalRangeValue;
bool onAdjustRangeValue(const String &deviceId, int &rangeValueDelta) {
globalRangeValue += rangeValue; // calculate absolute rangeValue
Serial.printf("Device %s range value has been changed about %i to %d\r\n", deviceId.c_str(), rangeValueDelta, globalRangeValue);
rangeValueDelta = globalRangeValue; // return absolute rangeValue
return true; // request handled properly
}
void onAdjustRangeValue(AdjustRangeValueCallback cb)
Set callback function for adjustRangeValue request.
Definition: RangeController.h:129

◆ GenericAdjustRangeValueCallback

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

Callback definition for onAdjustRangeValue function on a specific instance for custom devices.

Gets called when device receive a adjustRangeValue reuqest

Parameters
[in]deviceIdString which contains the ID of device
[in]instanceString instance name
[in]rangeValueInteger -3..3 delta value for range value have to change
[out]rangeValueInteger 3..3 returning the absolute range value
Returns
the success of the request
Return values
truerequest handled properly
falserequest was not handled properly because of some error

Example-Code

int globalRangeValue;
bool onAdjustRangeValue(const String &deviceId, const String& instance, int &rangeValueDelta) {
globalRangeValue += rangeValueDelta; // calculate absolute rangeValue
Serial.printf("Device %s range value for %s has been changed about %i to %d\r\n", deviceId.c_str(), instance.c_str(), rangeValueDelta, globalRangeValue);
rangeValueDelta = globalRangeValue; // return absolute rangeValue
return true; // request handled properly
}

◆ GenericSetRangeValueCallback

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

Callback definition for onRangeValue function on a specific instance.

Gets called when device receive a setRangeValue reuqest

Parameters
[in]deviceIdString which contains the ID of device
[in]instanceString instance name
[in]rangeValueInteger 0..3 for range value device has to be set
[out]rangeValueInteger 0..3 returning the current range value
Returns
the success of the request
Return values
truerequest handled properly
falserequest was not handled properly because of some error

Example-Code

bool onRangeValue(const String &deviceId, const String &instance, int &rangeValue) {
Serial.printf("Device %s range value for %s has been set to %d\r\n", deviceId.c_str(), instance.c_str(), rangeValue);
return true; // request handled properly
}
void onRangeValue(SetRangeValueCallback cb)
Set callback function for setRangeValue request.
Definition: RangeController.h:106

◆ 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

◆ SetRangeValueCallback

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

Callback definition for onRangeValue function.

Gets called when device receive a setRangeValue reuqest

Parameters
[in]deviceIdString which contains the ID of device
[in]rangeValueInteger 0..3 for range value device has to be set
[out]rangeValueInteger 0..3 returning the current range value
Returns
the success of the request
Return values
truerequest handled properly
falserequest was not handled properly because of some error

Example-Code

bool onRangeValue(const String &deviceId, int &rangeValue) {
Serial.printf("Device %s range value has been set to %d\r\n", deviceId.c_str(), rangeValue);
return true; // request handled properly
}

Member Function Documentation

◆ onAdjustRangeValue()

void onAdjustRangeValue ( AdjustRangeValueCallback  cb)
inherited

Set callback function for adjustRangeValue request.

Parameters
cbFunction pointer to a AdjustRangeValueCallback function
See also
AdjustRangeValueCallback

◆ onPowerState()

void onPowerState ( PowerStateCallback  cb)
inherited

Set callback function for powerState request.

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

◆ onRangeValue() [1/2]

void onRangeValue ( const String &  instance,
GenericSetRangeValueCallback  cb 
)
inherited

Set callback function for setRangeValue request on a specific instance (custom device)

Parameters
instanceString instance name (custom device)
cbFunction pointer to a GenericSetRangeValueCallback function
See also
GenericSetRangeValueCallback

◆ onRangeValue() [2/2]

void onRangeValue ( SetRangeValueCallback  cb)
inherited

Set callback function for setRangeValue request.

Parameters
cbFunction pointer to a SetRangeValueCallback function
See also
SetRangeValueCallback

◆ 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

◆ sendRangeValueEvent() [1/2]

bool sendRangeValueEvent ( const String &  instance,
int  rangeValue,
String  cause = "PHYSICAL_INTERACTION" 
)
inherited

Send rangeValue event to report curent rangeValue to SinricPro server for a specific instance (custom device)

Parameters
instanceString instance name
rangeValueValue between 0..3
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

◆ sendRangeValueEvent() [2/2]

bool sendRangeValueEvent ( int  rangeValue,
String  cause = "PHYSICAL_INTERACTION" 
)
inherited

Send rangeValue event to report curent rangeValue to SinricPro server.

Parameters
rangeValueValue between 0..3
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