]> git.basschouten.com Git - openhab-addons.git/blob
2a0851b2d48d29550ab1123311a3357d1748ef06
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.io.openhabcloud;
14
15 import org.openhab.core.model.script.engine.action.ActionDoc;
16 import org.openhab.io.openhabcloud.internal.CloudService;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 /**
21  * This class provides static methods that can be used in automation rules
22  * for sending notifications to the native apps.
23  *
24  * @author Victor Belov - Initial contribution
25  * @author Kai Kreuzer - migrated code to ESH APIs
26  *
27  */
28
29 public class NotificationAction {
30
31     private static final Logger logger = LoggerFactory.getLogger(NotificationAction.class);
32
33     public static CloudService cloudService = null;
34
35     /**
36      * Sends a simple push notification to mobile devices of user
37      *
38      * @param userId the cloud user id of the recipient
39      * @param message the body of the notification
40      *
41      */
42     @ActionDoc(text = "Sends a push notification to mobile devices of user with userId")
43     public static void sendNotification(String userId, String message) {
44         sendNotification(userId, message, null, null);
45     }
46
47     /**
48      * Sends an advanced push notification to mobile devices of user
49      *
50      * @param userId the cloud user id of the recipient
51      * @param message the body of the notification
52      * @param icon name for the notification
53      * @param severity category for the notification
54      *
55      */
56     @ActionDoc(text = "Sends a push notification to mobile devices of user with userId")
57     public static void sendNotification(String userId, String message, String icon, String severity) {
58         logger.debug("sending notification '{}' to user {}", message, userId);
59         if (cloudService != null) {
60             cloudService.sendNotification(userId, message, icon, severity);
61         }
62     }
63
64     /**
65      * Sends a simple notification to log. Log notifications are not pushed to user
66      * devices but are shown to all account users in notifications log.
67      *
68      * @param message the body of the notification
69      *
70      */
71     @ActionDoc(text = "Sends a log notification which is shown in notifications log to all account users")
72     public static void sendLogNotification(String message) {
73         sendLogNotification(message, null, null);
74     }
75
76     /**
77      * Sends an advanced notification to log. Log notifications are not pushed to user
78      * devices but are shown to all account users in notifications log.
79      *
80      * @param message the body of the notification
81      * @param icon name for the notification
82      * @param severity category for the notification
83      *
84      */
85     @ActionDoc(text = "Sends a log notification which is shown in notifications log to all account users")
86     public static void sendLogNotification(String message, String icon, String severity) {
87         logger.debug("sending log notification '{}'", message);
88         if (cloudService != null) {
89             cloudService.sendLogNotification(message, icon, severity);
90         }
91     }
92
93     /**
94      * Sends a simple broadcast notification. Broadcast notifications are pushed to all
95      * mobile devices of all users of the account
96      *
97      * @param message the body of the notification
98      *
99      */
100     @ActionDoc(text = "Sends a broadcast notification to all mobile devices of all account users")
101     public static void sendBroadcastNotification(String message) {
102         sendBroadcastNotification(message, null, null);
103     }
104
105     /**
106      * Sends an advanced broadcast notification. Broadcast notifications are pushed to all
107      * mobile devices of all users of the account
108      *
109      * @param message the body of the notification
110      * @param icon name for the notification
111      * @param severity category for the notification
112      *
113      */
114     @ActionDoc(text = "Sends a push notification to mobile devices of user with userId")
115     public static void sendBroadcastNotification(String message, String icon, String severity) {
116         logger.debug("sending broadcast notification '{}' to all users", message);
117         if (cloudService != null) {
118             cloudService.sendBroadcastNotification(message, icon, severity);
119         }
120     }
121 }