]> git.basschouten.com Git - openhab-addons.git/blob
93bdc1d6cc897e249c3ee708aed325a25e054e5e
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.core.model.script.engine.action.ActionDoc;
18 import org.openhab.io.openhabcloud.internal.CloudService;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 /**
23  * This class provides static methods that can be used in automation rules
24  * for sending notifications to the native apps.
25  *
26  * @author Victor Belov - Initial contribution
27  * @author Kai Kreuzer - migrated code to ESH APIs
28  */
29 @NonNullByDefault
30 public class NotificationAction {
31
32     private static final Logger logger = LoggerFactory.getLogger(NotificationAction.class);
33
34     public static @Nullable CloudService cloudService;
35
36     /**
37      * Sends a simple push notification to mobile devices of user
38      *
39      * @param userId the cloud user id of the recipient
40      * @param message the body of the notification
41      *
42      */
43     @ActionDoc(text = "Sends a push notification to mobile devices of user with userId")
44     public static void sendNotification(String userId, String message) {
45         sendNotification(userId, message, null, null);
46     }
47
48     /**
49      * Sends an advanced push notification to mobile devices of user
50      *
51      * @param userId the cloud user id of the recipient
52      * @param message the body of the notification
53      * @param icon name for the notification
54      * @param severity category for the notification
55      *
56      */
57     @ActionDoc(text = "Sends a push notification to mobile devices of user with userId")
58     public static void sendNotification(String userId, String message, @Nullable String icon,
59             @Nullable String severity) {
60         logger.debug("sending notification '{}' to user {}", message, userId);
61         if (cloudService != null) {
62             cloudService.sendNotification(userId, message, icon, severity);
63         }
64     }
65
66     /**
67      * Sends a simple notification to log. Log notifications are not pushed to user
68      * devices but are shown to all account users in notifications log.
69      *
70      * @param message the body of the notification
71      *
72      */
73     @ActionDoc(text = "Sends a log notification which is shown in notifications log to all account users")
74     public static void sendLogNotification(String message) {
75         sendLogNotification(message, null, null);
76     }
77
78     /**
79      * Sends an advanced notification to log. Log notifications are not pushed to user
80      * devices but are shown to all account users in notifications log.
81      *
82      * @param message the body of the notification
83      * @param icon name for the notification
84      * @param severity category for the notification
85      *
86      */
87     @ActionDoc(text = "Sends a log notification which is shown in notifications log to all account users")
88     public static void sendLogNotification(String message, @Nullable String icon, @Nullable String severity) {
89         logger.debug("sending log notification '{}'", message);
90         if (cloudService != null) {
91             cloudService.sendLogNotification(message, icon, severity);
92         }
93     }
94
95     /**
96      * Sends a simple broadcast notification. Broadcast notifications are pushed to all
97      * mobile devices of all users of the account
98      *
99      * @param message the body of the notification
100      *
101      */
102     @ActionDoc(text = "Sends a broadcast notification to all mobile devices of all account users")
103     public static void sendBroadcastNotification(String message) {
104         sendBroadcastNotification(message, null, null);
105     }
106
107     /**
108      * Sends an advanced broadcast notification. Broadcast notifications are pushed to all
109      * mobile devices of all users of the account
110      *
111      * @param message the body of the notification
112      * @param icon name for the notification
113      * @param severity category for the notification
114      *
115      */
116     @ActionDoc(text = "Sends a push notification to mobile devices of user with userId")
117     public static void sendBroadcastNotification(String message, @Nullable String icon, @Nullable String severity) {
118         logger.debug("sending broadcast notification '{}' to all users", message);
119         if (cloudService != null) {
120             cloudService.sendBroadcastNotification(message, icon, severity);
121         }
122     }
123 }