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+
12+ /* *
13+ * @brief PushNotification
14+ * @ingroup Capabilities
15+ **/
16+ template <typename T>
17+ class PushNotification {
18+ public:
19+ PushNotification ();
20+ bool sendPushNotification (String notification);
21+ private:
22+ EventLimiter event_limiter;
23+ };
24+
25+ template <typename T>
26+ PushNotification<T>::PushNotification()
27+ : event_limiter (EVENT_LIMIT_SENSOR_VALUE) {}
28+
29+ /* *
30+ * @brief Sending push notifications to SinricPro App
31+ *
32+ * @param notification `String` with the notification
33+ * @return the success of sending the event
34+ * @retval true event has been sent successfully
35+ * @retval false event has not been sent, maybe you sent to much events in a short distance of time
36+ **/
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+ DynamicJsonDocument 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>;
0 commit comments