]> git.basschouten.com Git - openhab-addons.git/blob
47d79892712ef38a082122eff1052e3a6a7429b5
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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  */
28 @NonNullByDefault
29 public class SendNotificationActionHandler extends BaseNotificationActionHandler {
30
31     public static final String TYPE_ID = "notification.SendNotification";
32     public static final String EXTENDED_TYPE_ID = "notification.SendExtendedNotification";
33     public static final String PARAM_USER = "userId";
34
35     private final String userId;
36
37     public SendNotificationActionHandler(Action module, CloudService cloudService) {
38         super(module, cloudService);
39
40         Object userIdParam = module.getConfiguration().get(PARAM_USER);
41         if (userIdParam instanceof String) {
42             this.userId = userIdParam.toString();
43         } else {
44             throw new IllegalArgumentException(String.format("Param '%s' should be of type String.", PARAM_USER));
45         }
46     }
47
48     @Override
49     public @Nullable Map<String, Object> execute(Map<String, Object> context) {
50         cloudService.sendNotification(userId, message, icon, severity);
51         return null;
52     }
53 }