SinricPro Library
ContactSensor.h
1 #ifndef _CONTACTSENSOR_H_
2 #define _CONTACTSENSOR_H_
3 
8 template <typename T>
9 class ContactSensor {
10  public:
11  bool sendContactEvent(bool detected, String cause = "PHYSICAL_INTERACTION");
12 };
13 
22 template <typename T>
23 bool ContactSensor<T>::sendContactEvent(bool detected, String cause) {
24  T& device = static_cast<T&>(*this);
25 
26  DynamicJsonDocument eventMessage = device.prepareEvent("setContactState", cause.c_str());
27  JsonObject event_value = eventMessage["payload"]["value"];
28  event_value["state"] = detected ? "closed" : "open";
29  return device.sendEvent(eventMessage);
30 }
31 
32 #endif
ContactSensor.
Definition: ContactSensor.h:9
bool sendContactEvent(bool detected, String cause="PHYSICAL_INTERACTION")
Send setContactState event to SinricPro Server indicating actual power state.
Definition: ContactSensor.h:23