SinricPro Library
PushNotification.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(PUSHNOTIFICATION, pushNotification); // "pushNotification"
10 FSTR(PUSHNOTIFICATION, alert); // "alert"
11 
16 template <typename T>
18  public:
20  bool sendPushNotification(String notification);
21  private:
22  EventLimiter event_limiter;
23 };
24 
25 template <typename T>
27 : event_limiter (EVENT_LIMIT_SENSOR_VALUE) {}
28 
37 template <typename T>
38 bool PushNotification<T>::sendPushNotification(String notification) {
39  if (event_limiter) return false;
40  T* device = static_cast<T*>(this);
41 
42  JsonDocument eventMessage = device->prepareEvent(FSTR_PUSHNOTIFICATION_pushNotification, FSTR_SINRICPRO_ALERT);
43  JsonObject event_value = eventMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_value];
44 
45  event_value[FSTR_PUSHNOTIFICATION_alert] = notification;
46 
47  return device->sendEvent(eventMessage);
48 }
49 
50 } // SINRICPRO_NAMESPACE
51 
52 template <typename T>
53 using PushNotification = SINRICPRO_NAMESPACE::PushNotification<T>;
PushNotification.
Definition: PushNotification.h:17
bool sendPushNotification(String notification)
Sending push notifications to SinricPro App.
Definition: PushNotification.h:38