2 * Copyright (c) 2010-2024 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.internal.actions;
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.core.config.core.ConfigParser;
21 import org.openhab.io.openhabcloud.internal.CloudService;
24 * This is a base {@link ModuleHandler} implementation for {@link Action}s to send a notifications via openHAB Cloud.
26 * @author Christoph Weitkamp - Initial contribution
27 * @author Dan Cunningham - Extended notification enhancements
30 public abstract class BaseNotificationActionHandler extends BaseActionModuleHandler {
32 public static final String PARAM_MESSAGE = "message";
33 public static final String PARAM_ICON = "icon";
34 public static final String PARAM_SEVERITY = "severity";
35 public static final String PARAM_TITLE = "title";
36 public static final String PARAM_ON_CLICK_ACTION = "onClickAction";
37 public static final String PARAM_MEDIA_ATTACHMENT_URL = "mediaAttachmentUrl";
38 public static final String PARAM_ACTION_BUTTON_1 = "actionButton1";
39 public static final String PARAM_ACTION_BUTTON_2 = "actionButton2";
40 public static final String PARAM_ACTION_BUTTON_3 = "actionButton3";
42 protected final CloudService cloudService;
44 protected final String message;
45 protected final @Nullable String icon;
46 protected final @Nullable String severity;
47 protected final @Nullable String title;
48 protected final @Nullable String onClickAction;
49 protected final @Nullable String mediaAttachmentUrl;
50 protected final @Nullable String actionButton1;
51 protected final @Nullable String actionButton2;
52 protected final @Nullable String actionButton3;
54 public BaseNotificationActionHandler(Action module, CloudService cloudService) {
56 this.cloudService = cloudService;
58 Object messageParam = module.getConfiguration().get(PARAM_MESSAGE);
59 if (messageParam instanceof String) {
60 this.message = messageParam.toString();
62 throw new IllegalArgumentException(String.format("Param '%s' should be of type String.", PARAM_MESSAGE));
65 this.icon = stringConfig(PARAM_ICON);
66 this.severity = stringConfig(PARAM_SEVERITY);
67 this.title = stringConfig(PARAM_TITLE);
68 this.onClickAction = stringConfig(PARAM_ON_CLICK_ACTION);
69 this.mediaAttachmentUrl = stringConfig(PARAM_MEDIA_ATTACHMENT_URL);
70 this.actionButton1 = stringConfig(PARAM_ACTION_BUTTON_1);
71 this.actionButton2 = stringConfig(PARAM_ACTION_BUTTON_2);
72 this.actionButton3 = stringConfig(PARAM_ACTION_BUTTON_3);
75 private @Nullable String stringConfig(String key) {
76 return ConfigParser.valueAs(module.getConfiguration().get(key), String.class);