8 #ifndef _SINRICLIGHT_H_
9 #define _SINRICLIGHT_H_
11 #include "SinricProDevice.h"
25 SinricProLight(
const char* deviceId,
unsigned long eventWaitTime=100);
75 typedef std::function<bool(
const String&,
byte&,
byte&,
byte&)>
ColorCallback;
131 bool sendColorEvent(
byte r,
byte g,
byte b, String cause =
"PHYSICAL_INTERACTION");
135 bool handleRequest(
const char* deviceId,
const char* action, JsonObject &request_value, JsonObject &response_value)
override;
145 SinricProLight::SinricProLight(
const char* deviceId,
unsigned long eventWaitTime) :
SinricProDevice(deviceId, eventWaitTime),
146 brightnessCallback(nullptr),
147 adjustBrightnessCallback(nullptr),
148 colorCallback(nullptr),
149 colorTemperatureCallback(nullptr),
150 increaseColorTemperatureCallback(nullptr),
151 decreaseColorTemperatureCallback(nullptr) {}
153 bool SinricProLight::handleRequest(
const char* deviceId,
const char* action, JsonObject &request_value, JsonObject &response_value) {
154 if (strcmp(deviceId, this->deviceId) != 0)
return false;
155 if (SinricProDevice::handleRequest(deviceId, action, request_value, response_value))
return true;
157 bool success =
false;
158 String actionString = String(action);
160 if (brightnessCallback && actionString ==
"setBrightness") {
161 int brightness = request_value[
"brightness"];
162 success = brightnessCallback(String(deviceId), brightness);
163 response_value[
"brightness"] = brightness;
166 if (adjustBrightnessCallback && actionString ==
"adjustBrightness") {
167 int brightnessDelta = request_value[
"brightnessDelta"];
168 success = adjustBrightnessCallback(String(deviceId), brightnessDelta);
169 response_value[
"brightness"] = brightnessDelta;
172 if (colorCallback && actionString ==
"setColor") {
173 unsigned char r, g, b;
174 r = request_value[
"color"][
"r"];
175 g = request_value[
"color"][
"g"];
176 b = request_value[
"color"][
"b"];
177 success = colorCallback(String(deviceId), r, g, b);
178 response_value.createNestedObject(
"color");
179 response_value[
"color"][
"r"] = r;
180 response_value[
"color"][
"g"] = g;
181 response_value[
"color"][
"b"] = b;
184 if (colorTemperatureCallback && actionString ==
"setColorTemperature") {
185 int colorTemperature = request_value[
"colorTemperature"];
186 success = colorTemperatureCallback(String(deviceId), colorTemperature);
187 response_value[
"colorTemperature"] = colorTemperature;
190 if (increaseColorTemperatureCallback && actionString ==
"increaseColorTemperature") {
191 int colorTemperature = 1;
192 success = increaseColorTemperatureCallback(String(deviceId), colorTemperature);
193 response_value[
"colorTemperature"] = colorTemperature;
196 if (decreaseColorTemperatureCallback && actionString ==
"decreaseColorTemperature") {
197 int colorTemperature = -1;
198 success = decreaseColorTemperatureCallback(String(deviceId), colorTemperature);
199 response_value[
"colorTemperature"] = colorTemperature;
213 brightnessCallback = cb;
224 adjustBrightnessCallback = cb;
246 colorTemperatureCallback = cb;
257 increaseColorTemperatureCallback = cb;
268 decreaseColorTemperatureCallback = cb;
281 DynamicJsonDocument eventMessage = prepareEvent(deviceId,
"setBrightness", cause.c_str());
282 JsonObject event_value = eventMessage[
"payload"][
"value"];
283 event_value[
"brightness"] = brightness;
284 return sendEvent(eventMessage);
299 DynamicJsonDocument eventMessage = prepareEvent(deviceId,
"setColor", cause.c_str());
300 JsonObject event_color = eventMessage[
"payload"][
"value"].createNestedObject(
"color");
301 event_color[
"r"] = r;
302 event_color[
"g"] = g;
303 event_color[
"b"] = b;
304 return sendEvent(eventMessage);
317 DynamicJsonDocument eventMessage = prepareEvent(deviceId,
"setColorTemperature", cause.c_str());
318 JsonObject event_value = eventMessage[
"payload"][
"value"];
319 event_value[
"colorTemperature"] = colorTemperature;
320 return sendEvent(eventMessage);