2 * Copyright (c) 2010-2022 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.io.openhabcloud;
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;
23 * This class provides static methods that can be used in automation rules
24 * for sending notifications to the native apps.
26 * @author Victor Belov - Initial contribution
27 * @author Kai Kreuzer - migrated code to ESH APIs
30 public class NotificationAction {
32 private static final Logger logger = LoggerFactory.getLogger(NotificationAction.class);
34 public static @Nullable CloudService cloudService;
37 * Sends a simple push notification to mobile devices of user
39 * @param userId the cloud user id of the recipient
40 * @param message the body of the notification
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);
49 * Sends an advanced push notification to mobile devices of user
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
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);
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.
70 * @param message the body of the notification
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);
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.
82 * @param message the body of the notification
83 * @param icon name for the notification
84 * @param severity category for the notification
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);
96 * Sends a simple broadcast notification. Broadcast notifications are pushed to all
97 * mobile devices of all users of the account
99 * @param message the body of the notification
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);
108 * Sends an advanced broadcast notification. Broadcast notifications are pushed to all
109 * mobile devices of all users of the account
111 * @param message the body of the notification
112 * @param icon name for the notification
113 * @param severity category for the notification
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);