8 #ifndef _SINRICTHERMOSTAT_H_
9 #define _SINRICTHERMOSTAT_H_
11 #include "SinricProDevice.h"
81 bool sendTemperatureEvent(
float temperature,
float humidity = -1, String cause =
"PERIODIC_POLL");
86 bool handleRequest(
const char* deviceId,
const char* action, JsonObject &request_value, JsonObject &response_value)
override;
93 SinricProThermostat::SinricProThermostat(
const char* deviceId,
unsigned long eventWaitTime) :
SinricProDevice(deviceId, eventWaitTime),
94 targetTemperatureCallback(nullptr),
95 adjustTargetTemperatureCallback(nullptr),
96 thermostatModeCallback(nullptr) {}
98 bool SinricProThermostat::handleRequest(
const char* deviceId,
const char* action, JsonObject &request_value, JsonObject &response_value) {
99 if (strcmp(deviceId, this->deviceId) != 0)
return false;
100 if (SinricProDevice::handleRequest(deviceId, action, request_value, response_value))
return true;
102 bool success =
false;
103 String actionString = String(action);
105 if (actionString ==
"targetTemperature" && targetTemperatureCallback) {
107 if (request_value.containsKey(
"temperature")) {
108 temperature = request_value[
"temperature"];
112 success = targetTemperatureCallback(String(deviceId), temperature);
113 response_value[
"temperature"] = temperature;
117 if (actionString ==
"adjustTargetTemperature" && adjustTargetTemperatureCallback) {
118 float temperatureDelta = request_value[
"temperature"];
119 success = adjustTargetTemperatureCallback(String(deviceId), temperatureDelta);
120 response_value[
"temperature"] = temperatureDelta;
124 if (actionString ==
"setThermostatMode" && thermostatModeCallback) {
125 String thermostatMode = request_value[
"thermostatMode"] |
"";
126 success = thermostatModeCallback(String(deviceId), thermostatMode);
127 response_value[
"thermostatMode"] = thermostatMode;
142 targetTemperatureCallback = cb;
153 adjustTargetTemperatureCallback = cb;
164 thermostatModeCallback = cb;
178 DynamicJsonDocument eventMessage = prepareEvent(deviceId,
"currentTemperature", cause.c_str());
179 JsonObject event_value = eventMessage[
"payload"][
"value"];
180 event_value[
"humidity"] = humidity;
181 event_value[
"temperature"] = roundf(temperature *10) / 10;
182 return sendEvent(eventMessage);
195 DynamicJsonDocument eventMessage = prepareEvent(deviceId,
"targetTemperature", cause.c_str());
196 JsonObject event_value = eventMessage[
"payload"][
"value"];
197 event_value[
"temperature"] = roundf(temperature * 10) / 10.0;
198 return sendEvent(eventMessage);
211 DynamicJsonDocument eventMessage = prepareEvent(deviceId,
"setThermostatMode", cause.c_str());
212 JsonObject event_value = eventMessage[
"payload"][
"value"];
213 event_value[
"thermostatMode"] = thermostatMode;
214 return sendEvent(eventMessage);