SinricPro Library
SinricProLight

Device to control a light. More...

Inheritance diagram for SinricProLight:

Public Types

using PowerStateCallback = std::function< bool(const String &, bool &)>
 Callback definition for onPowerState function. More...
 
using BrightnessCallback = std::function< bool(const String &, int &)>
 Callback definition for onBrightness function. More...
 
using AdjustBrightnessCallback = std::function< bool(const String &, int &)>
 Callback definition for onAdjustBrightness function. More...
 
using ColorCallback = std::function< bool(const String &, byte &, byte &, byte &)>
 Callback definition for onColor function. More...
 
using ColorTemperatureCallback = std::function< bool(const String &, int &)>
 Callback definition for onColorTemperature function. More...
 
using IncreaseColorTemperatureCallback = std::function< bool(const String &, int &)>
 Callback definition for onIncreaseColorTemperature function. More...
 
using DecreaseColorTemperatureCallback = std::function< bool(const String &, int &)>
 Callback definition for onDecreaseColorTemperature function. 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 onBrightness (BrightnessCallback cb)
 Set callback function for setBrightness request. More...
 
void onAdjustBrightness (AdjustBrightnessCallback cb)
 Set callback function for adjustBrightness request. More...
 
bool sendBrightnessEvent (int brightness, String cause="PHYSICAL_INTERACTION")
 Send setBrightness event to SinricPro Server indicating actual brightness. More...
 
void onColor (ColorCallback cb)
 Set callback function for setColor request. More...
 
bool sendColorEvent (byte r, byte g, byte b, String cause="PHYSICAL_INTERACTION")
 Send setColor event to SinricPro Server indicating actual color. More...
 
void onColorTemperature (ColorTemperatureCallback cb)
 Set callback function for setColorTemperature request. More...
 
void onIncreaseColorTemperature (IncreaseColorTemperatureCallback cb)
 Set callback function for increaseColorTemperature request. More...
 
void onDecreaseColorTemperature (DecreaseColorTemperatureCallback cb)
 Set callback function for decreaseColorTemperature request. More...
 
bool sendColorTemperatureEvent (int colorTemperature, String cause="PHYSICAL_INTERACTION")
 Send setColorTemperature event to SinricPro Server indicating actual color temperature. More...
 

Detailed Description

Device to control a light.

Supporting

  • On / Off
  • Brightness (0..100)
  • Color (RGB)
  • Color temperature

Member Typedef Documentation

◆ AdjustBrightnessCallback

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

Callback definition for onAdjustBrightness function.

Gets called when device receive a adjustBrightness request

Parameters
[in]deviceIdString which contains the ID of device
[in]brightnessRelative integer value the device should change the brightness about
[out]brightnessAbsolute integer value with new brightness the device is 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 absoluteBrightness;
bool onAdjustBrightness(const String &deviceId, int &brightnessDelta) {
absoluteBrightness += brightnessDelta; // calculate absolute brigthness
Serial.printf("Device %s brightness changed about %i to %d\r\n", deviceId.c_str(), brightnessDelta, absoluteBrightness);
brightnessDelta = absoluteBrightness; // return absolute brightness
return true; // request handled properly
}
void onAdjustBrightness(AdjustBrightnessCallback cb)
Set callback function for adjustBrightness request.
Definition: BrightnessController.h:77

◆ BrightnessCallback

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

Callback definition for onBrightness function.

Gets called when device receive a setBrightness request

Parameters
[in]deviceIdString which contains the ID of device
[in]brightnessAbsolute integer value the device should set its brightness to
[out]brightnessAbsolute integer value with new brightness the device is 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 onBrightness(const String &deviceId, int &brightness) {
Serial.printf("Device %s brightness %d\r\n", deviceId.c_str(), brightness);
return true; // request handled properly
}
void onBrightness(BrightnessCallback cb)
Set callback function for setBrightness request.
Definition: BrightnessController.h:65

◆ ColorCallback

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

Callback definition for onColor function.

Gets called when device receive a setColor request

Parameters
[in]deviceIdString which contains the ID of device
[in]rByte value for red
[in]gByte value for green
[in]bByte value for blue
[out]rByte value for red
[out]gByte value for green
[out]bByte value for blue
Returns
the success of the request
Return values
truerequest handled properly
falserequest was not handled properly because of some error

Example-Code

bool onColor(const String &deviceId, byte &r, byte &g, byte &b) {
Serial.printf("Device %s color is set to red=%d, green=%d, blue=%d\r\n", deviceId.c_str(), r, g, b);
return true; // request handled properly
}
void onColor(ColorCallback cb)
Set callback function for setColor request.
Definition: ColorController.h:52

◆ ColorTemperatureCallback

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

Callback definition for onColorTemperature function.

Gets called when device receive a setColorTemperature request

Parameters
[in]deviceIdString which contains the ID of device
[in]colorTemperatureInteger value with color temperature the device should set to
2200 = warm white
2700 = soft white
4000 = white
5500 = daylight white
7000 = cool white
[out]colorTemperatureInteger value with color temperature the device is set to
2200 = warm white
2700 = soft white
4000 = white
5500 = daylight white
7000 = cool white
Returns
the success of the request
Return values
truerequest handled properly
falserequest was not handled properly because of some error

Example-Code

bool onColorTemperature(const String &deviceId, int &colorTemperature) {
Serial.printf("Device %s colorTemperature is set to %i\r\n", deviceId.c_str(), colorTemperature);
return true; // request handled properly
}
void onColorTemperature(ColorTemperatureCallback cb)
Set callback function for setColorTemperature request.
Definition: ColorTemperatureController.h:82

◆ DecreaseColorTemperatureCallback

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

Callback definition for onDecreaseColorTemperature function.

Gets called when device receive a decreaseColorTemperature request

Parameters
[in]deviceIdString which contains the ID of device
[in]colorTemperatureInteger value -1 = Device should decrease color temperature
[out]colorTemperatureInteger value return the new color temperarature
2200 = warm white
2700 = soft white
4000 = white
5500 = daylight white
7000 = cool white
Returns
the success of the request
Return values
truerequest handled properly
falserequest was not handled properly because of some error

Example-Code

int globalColorTemperature;
bool onDecreaseColorTemperature(const String &deviceId, int &colorTemperature) {
globalColorTemperature -= 1000; // decrease globalColorTemperature about 1000;
Serial.printf("Device %s colorTemperature changed %i\r\n", deviceId.c_str(), colorTemperature);
colorTemperature = globalColorTemperature; // return new colorTemperature
return true; // request handled properly
}
void onDecreaseColorTemperature(DecreaseColorTemperatureCallback cb)
Set callback function for decreaseColorTemperature request.
Definition: ColorTemperatureController.h:106

◆ IncreaseColorTemperatureCallback

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

Callback definition for onIncreaseColorTemperature function.

Gets called when device receive a increaseColorTemperature request

Parameters
[in]deviceIdString which contains the ID of device
[in]colorTemperatureInteger value 1 = Device should increase color temperature
[out]colorTemperatureInteger value return the new color temperarature
2200 = warm white
2700 = soft white
4000 = white
5500 = daylight white
7000 = cool white
Returns
the success of the request
Return values
truerequest handled properly
falserequest was not handled properly because of some error

Example-Code

int globalColorTemperature;
bool onIncreaseColorTemperature(const String &deviceId, int &colorTemperature) {
globalColorTemperature += 1000; // increase globalColorTemperature about 1000;
Serial.printf("Device %s colorTemperature changed to %i\r\n", deviceId.c_str(), colorTemperature);
colorTemperature = globalColorTemperature; // return new colorTemperature
return true; // request handled properly
}
void onIncreaseColorTemperature(IncreaseColorTemperatureCallback cb)
Set callback function for increaseColorTemperature request.
Definition: ColorTemperatureController.h:94

◆ 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

Member Function Documentation

◆ onAdjustBrightness()

void onAdjustBrightness ( AdjustBrightnessCallback  cb)
inherited

Set callback function for adjustBrightness request.

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

◆ onBrightness()

void onBrightness ( BrightnessCallback  cb)
inherited

Set callback function for setBrightness request.

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

◆ onColor()

void onColor ( ColorCallback  cb)
inherited

Set callback function for setColor request.

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

◆ onColorTemperature()

void onColorTemperature ( ColorTemperatureCallback  cb)
inherited

Set callback function for setColorTemperature request.

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

◆ onDecreaseColorTemperature()

void onDecreaseColorTemperature ( DecreaseColorTemperatureCallback  cb)
inherited

Set callback function for decreaseColorTemperature request.

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

◆ onIncreaseColorTemperature()

void onIncreaseColorTemperature ( IncreaseColorTemperatureCallback  cb)
inherited

Set callback function for increaseColorTemperature request.

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

◆ onPowerState()

void onPowerState ( PowerStateCallback  cb)
inherited

Set callback function for powerState request.

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

◆ sendBrightnessEvent()

bool sendBrightnessEvent ( int  brightness,
String  cause = "PHYSICAL_INTERACTION" 
)
inherited

Send setBrightness event to SinricPro Server indicating actual brightness.

Parameters
brightnessInteger value with actual brightness the device is set to
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

◆ sendColorEvent()

bool sendColorEvent ( byte  r,
byte  g,
byte  b,
String  cause = "PHYSICAL_INTERACTION" 
)
inherited

Send setColor event to SinricPro Server indicating actual color.

Parameters
rByte value for red
gByte value for green
bByte value for blue
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

◆ sendColorTemperatureEvent()

bool sendColorTemperatureEvent ( int  colorTemperature,
String  cause = "PHYSICAL_INTERACTION" 
)
inherited

Send setColorTemperature event to SinricPro Server indicating actual color temperature.

Parameters
colorTemperatureInteger with new color temperature the device is set to
2200 = warm white
2700 = soft white
4000 = white
5500 = daylight white
7000 = cool white
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

◆ 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