]> git.basschouten.com Git - openhab-addons.git/blob
afcb4d2abeedc5701c0ba0b07e9740072be2a24f
[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 org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.core.automation.Action;
18 import org.openhab.core.automation.handler.BaseActionModuleHandler;
19 import org.openhab.core.automation.handler.ModuleHandler;
20 import org.openhab.io.openhabcloud.internal.CloudService;
21
22 /**
23  * This is a base {@link ModuleHandler} implementation for {@link Action}s to send a notifications via openHAB Cloud.
24  *
25  * @author Christoph Weitkamp - Initial contribution
26  */
27 @NonNullByDefault
28 public abstract class BaseNotificationActionHandler extends BaseActionModuleHandler {
29
30     public static final String PARAM_MESSAGE = "message";
31     public static final String PARAM_ICON = "icon";
32     public static final String PARAM_SEVERITY = "severity";
33
34     protected final CloudService cloudService;
35
36     protected final String message;
37     protected final @Nullable String icon;
38     protected final @Nullable String severity;
39
40     public BaseNotificationActionHandler(Action module, CloudService cloudService) {
41         super(module);
42         this.cloudService = cloudService;
43
44         Object messageParam = module.getConfiguration().get(PARAM_MESSAGE);
45         if (messageParam instanceof String) {
46             this.message = messageParam.toString();
47         } else {
48             throw new IllegalArgumentException(String.format("Param '%s' should be of type String.", PARAM_MESSAGE));
49         }
50
51         Object iconParam = module.getConfiguration().get(PARAM_ICON);
52         this.icon = iconParam instanceof String ? iconParam.toString() : null;
53
54         Object severityParam = module.getConfiguration().get(PARAM_SEVERITY);
55         this.severity = severityParam instanceof String ? severityParam.toString() : null;
56     }
57 }