SinricPro Library
SinricProLight

Device to control a light. More...

Inheritance diagram for SinricProLight:
SinricProDevice

Public Types

typedef std::function< bool(const String &, int &)> BrightnessCallback
 Callback definition for onBrightness function. More...
 
typedef std::function< bool(const String &, int &)> AdjustBrightnessCallback
 Callback definition for onAdjustBrightness function. More...
 
typedef std::function< bool(const String &, byte &, byte &, byte &)> ColorCallback
 Callback definition for onColor function. More...
 
typedef std::function< bool(const String &, int &)> ColorTemperatureCallback
 Callback definition for onColorTemperature function. More...
 
typedef std::function< bool(const String &, int &)> IncreaseColorTemperatureCallback
 Callback definition for onIncreaseColorTemperature function. More...
 
typedef std::function< bool(const String &, int &)> DecreaseColorTemperatureCallback
 Callback definition for onDecreaseColorTemperature function. More...
 
typedef std::function< bool(const String &, bool &)> PowerStateCallback
 Callback definition for onPowerState function. More...
 

Public Member Functions

void onBrightness (BrightnessCallback cb)
 Set callback function for setBrightness request. More...
 
void onAdjustBrightness (AdjustBrightnessCallback cb)
 Set callback function for adjustBrightness request. More...
 
void onColor (ColorCallback cb)
 Set callback function for setColor request. 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 sendBrightnessEvent (int brightness, String cause="PHYSICAL_INTERACTION")
 Send setBrightness event to SinricPro Server indicating actual brightness. More...
 
bool sendColorEvent (byte r, byte g, byte b, String cause="PHYSICAL_INTERACTION")
 Send setColor event to SinricPro Server indicating actual color. More...
 
bool sendColorTemperatureEvent (int colorTemperature, String cause="PHYSICAL_INTERACTION")
 Send setColorTemperature event to SinricPro Server indicating actual color temperature. 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 to control a light.

Supporting

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

Member Typedef Documentation

◆ AdjustBrightnessCallback

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

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
}

◆ BrightnessCallback

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

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
}

◆ ColorCallback

typedef std::function<bool(const String&, byte&, byte&, byte&)> ColorCallback

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
}

◆ ColorTemperatureCallback

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

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
}

◆ DecreaseColorTemperatureCallback

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

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
}

◆ IncreaseColorTemperatureCallback

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

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
}

◆ 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
}

Member Function Documentation

◆ onAdjustBrightness()

void onAdjustBrightness ( AdjustBrightnessCallback  cb)

Set callback function for adjustBrightness request.

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

◆ onBrightness()

void onBrightness ( BrightnessCallback  cb)

Set callback function for setBrightness request.

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

◆ onColor()

void onColor ( ColorCallback  cb)

Set callback function for setColor request.

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

◆ onColorTemperature()

void onColorTemperature ( ColorTemperatureCallback  cb)

Set callback function for setColorTemperature request.

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

◆ onDecreaseColorTemperature()

void onDecreaseColorTemperature ( DecreaseColorTemperatureCallback  cb)

Set callback function for decreaseColorTemperature request.

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

◆ onIncreaseColorTemperature()

void onIncreaseColorTemperature ( IncreaseColorTemperatureCallback  cb)

Set callback function for increaseColorTemperature request.

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

◆ onPowerState()

void onPowerState ( PowerStateCallback  cb)
virtualinherited

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

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

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

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
SinricProLight::onIncreaseColorTemperature
void onIncreaseColorTemperature(IncreaseColorTemperatureCallback cb)
Set callback function for increaseColorTemperature request.
Definition: SinricProLight.h:256
SinricProLight::onDecreaseColorTemperature
void onDecreaseColorTemperature(DecreaseColorTemperatureCallback cb)
Set callback function for decreaseColorTemperature request.
Definition: SinricProLight.h:267
SinricProLight::onColorTemperature
void onColorTemperature(ColorTemperatureCallback cb)
Set callback function for setColorTemperature request.
Definition: SinricProLight.h:245
SinricProLight::onColor
void onColor(ColorCallback cb)
Set callback function for setColor request.
Definition: SinricProLight.h:234
SinricProLight::onAdjustBrightness
void onAdjustBrightness(AdjustBrightnessCallback cb)
Set callback function for adjustBrightness request.
Definition: SinricProLight.h:223
SinricProLight::onBrightness
void onBrightness(BrightnessCallback cb)
Set callback function for setBrightness request.
Definition: SinricProLight.h:212
SinricProDevice::onPowerState
virtual void onPowerState(PowerStateCallback cb)
Set callback function for powerState request.
Definition: SinricProDevice.h:157