SinricPro Library
SinricProContactsensor.h
1 /*
2  * Copyright (c) 2019 Sinric. All rights reserved.
3  * Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
4  *
5  * This file is part of the Sinric Pro (https://github.com/sinricpro/)
6  */
7 
8 #ifndef _SINRICCONTACTSENSOR_H_
9 #define _SINRICCONTACTSENSOR_H_
10 
11 #include "SinricProDevice.h"
12 
18  public:
19  SinricProContactsensor(const char* deviceId, unsigned long eventWaitTime=100);
20 
21  // event
22  bool sendContactEvent(bool detected, String cause = "PHYSICAL_INTERACTION");
23 
24  private:
25 };
26 
27 SinricProContactsensor::SinricProContactsensor(const char* deviceId, unsigned long eventWaitTime) : SinricProDevice(deviceId, eventWaitTime) {}
28 
37 bool SinricProContactsensor::sendContactEvent(bool state, String cause) {
38  DynamicJsonDocument eventMessage = prepareEvent(deviceId, "setContactState", cause.c_str());
39  JsonObject event_value = eventMessage["payload"]["value"];
40  event_value["state"] = state?"closed":"open";
41  return sendEvent(eventMessage);
42 }
43 
44 #endif
45 
SinricProContactsensor
Device to report contact sensor events.
Definition: SinricProContactsensor.h:17
SinricProContactsensor::sendContactEvent
bool sendContactEvent(bool detected, String cause="PHYSICAL_INTERACTION")
Send setContactState event to SinricPro Server indicating actual power state.
Definition: SinricProContactsensor.h:37
SinricProDevice
Base class for all device types.
Definition: SinricProDevice.h:23