SinricPro Library
MotionSensor.h
1 #pragma once
2 
3 #include "../EventLimiter.h"
4 #include "../SinricProStrings.h"
5 
6 #include "../SinricProNamespace.h"
7 namespace SINRICPRO_NAMESPACE {
8 
9 FSTR(MOTION, motion); // "motion"
10 FSTR(MOTION, state); // "state"
11 FSTR(MOTION, detected); // "detected"
12 FSTR(MOTION, notDetected); // "notDetected"
13 
18 template <typename T>
19 class MotionSensor {
20  public:
21  MotionSensor();
22  bool sendMotionEvent(bool detected, String cause = FSTR_SINRICPRO_PHYSICAL_INTERACTION);
23  private:
24  EventLimiter event_limiter;
25 };
26 
27 template <typename T>
29 : event_limiter(EVENT_LIMIT_SENSOR_STATE) {}
30 
40 template <typename T>
41 bool MotionSensor<T>::sendMotionEvent(bool detected, String cause) {
42  if (event_limiter) return false;
43  T* device = static_cast<T*>(this);
44 
45  JsonDocument eventMessage = device->prepareEvent(FSTR_MOTION_motion, cause.c_str());
46  JsonObject event_value = eventMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_value];
47  event_value[FSTR_MOTION_state] = detected ? FSTR_MOTION_detected : FSTR_MOTION_notDetected;
48  return device->sendEvent(eventMessage);
49 }
50 
51 } // SINRICPRO_NAMESPACE
52 
53 template <typename T>
54 using MotionSensor = SINRICPRO_NAMESPACE::MotionSensor<T>;
MotionSensor.
Definition: MotionSensor.h:19
bool sendMotionEvent(bool detected, String cause=FSTR_SINRICPRO_PHYSICAL_INTERACTION)
Sending motion detection state to SinricPro server.
Definition: MotionSensor.h:41