SinricPro Library
ToggleController< T >

ToggleController. More...

Public Types

using GenericToggleStateCallback = std::function< bool(const String &, const String &, bool &)>
 Callback definition for onToggleState function. More...
 

Public Member Functions

void onToggleState (const String &instance, GenericToggleStateCallback cb)
 Set callback function for toggleState request. More...
 
bool sendToggleStateEvent (const String &instance, bool state, String cause="PHYSICAL_INTERACTION")
 Send setToggleState event to SinricPro Server indicating actual toggle state. More...
 

Detailed Description

template<typename T>
class ToggleController< T >

ToggleController.

Member Typedef Documentation

◆ GenericToggleStateCallback

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

Callback definition for onToggleState function.

Gets called when device receive a setPowerState reuqest

Parameters
[in]deviceIdString which contains the ID of device
[in]instanceString which instance is requested
[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 onToggleState(const String &deviceId, const String &instance, bool &state) {
Serial.printf("Device %s state \"%s\" turned %s\r\n", deviceId.c_str(), instance.c_str(), state ? "on" : "off");
return true; // request handled properly
}
void onToggleState(const String &instance, GenericToggleStateCallback cb)
Set callback function for toggleState request.
Definition: ToggleController.h:50

Member Function Documentation

◆ onToggleState()

void onToggleState ( const String &  instance,
GenericToggleStateCallback  cb 
)

Set callback function for toggleState request.

Parameters
instanceString instance name (custom device)
cbFunction pointer to a ToggleStateCallback function
Returns
void
See also
ToggleStateCallback

◆ sendToggleStateEvent()

bool sendToggleStateEvent ( const String &  instance,
bool  state,
String  cause = "PHYSICAL_INTERACTION" 
)

Send setToggleState event to SinricPro Server indicating actual toggle state.

Parameters
instanceString instance name (custom device)
statetrue = state turned on
false = tate 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