]> git.basschouten.com Git - openhab-addons.git/blob
5ce6ac44b8acaf6ee45563035a983ca40268611f
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.internal.actions;
14
15 import java.util.Map;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.core.automation.Action;
20 import org.openhab.core.automation.handler.ModuleHandler;
21 import org.openhab.io.openhabcloud.internal.CloudService;
22
23 /**
24  * This is a {@link ModuleHandler} implementation for {@link Action}s to send a notification to a specific cloud user.
25  *
26  * @author Christoph Weitkamp - Initial contribution
27  * @author Dan Cunningham - Extended notification enhancements
28  */
29 @NonNullByDefault
30 public class SendNotificationActionHandler extends BaseNotificationActionHandler {
31
32     public static final String TYPE_ID = "notification.SendNotification";
33     public static final String EXTENDED_TYPE_ID = "notification.SendExtendedNotification";
34     public static final String EXTENDED2_TYPE_ID = "notification.SendExtended2Notification";
35
36     public static final String PARAM_USER = "userId";
37
38     private final String userId;
39
40     public SendNotificationActionHandler(Action module, CloudService cloudService) {
41         super(module, cloudService);
42
43         Object userIdParam = module.getConfiguration().get(PARAM_USER);
44         if (userIdParam instanceof String) {
45             this.userId = userIdParam.toString();
46         } else {
47             throw new IllegalArgumentException(String.format("Param '%s' should be of type String.", PARAM_USER));
48         }
49     }
50
51     @Override
52     public @Nullable Map<String, Object> execute(Map<String, Object> context) {
53         cloudService.sendNotification(userId, message, icon, severity, title, onClickAction, mediaAttachmentUrl,
54                 actionButton1, actionButton2, actionButton3);
55         return null;
56     }
57 }