2 * Copyright (c) 2010-2020 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.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;
21 * This class provides static methods that can be used in automation rules
22 * for sending notifications to the native apps.
24 * @author Victor Belov - Initial contribution
25 * @author Kai Kreuzer - migrated code to ESH APIs
29 public class NotificationAction {
31 private static final Logger logger = LoggerFactory.getLogger(NotificationAction.class);
33 public static CloudService cloudService = null;
36 * Sends a simple push notification to mobile devices of user
38 * @param userId the cloud user id of the recipient
39 * @param message the body of the notification
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);
48 * Sends an advanced push notification to mobile devices of user
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
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);
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.
68 * @param message the body of the notification
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);
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.
80 * @param message the body of the notification
81 * @param icon name for the notification
82 * @param severity category for the notification
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);
94 * Sends a simple broadcast notification. Broadcast notifications are pushed to all
95 * mobile devices of all users of the account
97 * @param message the body of the notification
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);
106 * Sends an advanced broadcast notification. Broadcast notifications are pushed to all
107 * mobile devices of all users of the account
109 * @param message the body of the notification
110 * @param icon name for the notification
111 * @param severity category for the notification
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);