2 * Copyright (c) 2010-2023 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.io.openhabcloud.internal.CloudService;
23 * This is a base {@link ModuleHandler} implementation for {@link Action}s to send a notifications via openHAB Cloud.
25 * @author Christoph Weitkamp - Initial contribution
28 public abstract class BaseNotificationActionHandler extends BaseActionModuleHandler {
30 public static final String PARAM_MESSAGE = "message";
31 public static final String PARAM_ICON = "icon";
32 public static final String PARAM_SEVERITY = "severity";
34 protected final CloudService cloudService;
36 protected final String message;
37 protected final @Nullable String icon;
38 protected final @Nullable String severity;
40 public BaseNotificationActionHandler(Action module, CloudService cloudService) {
42 this.cloudService = cloudService;
44 Object messageParam = module.getConfiguration().get(PARAM_MESSAGE);
45 if (messageParam instanceof String) {
46 this.message = messageParam.toString();
48 throw new IllegalArgumentException(String.format("Param '%s' should be of type String.", PARAM_MESSAGE));
51 Object iconParam = module.getConfiguration().get(PARAM_ICON);
52 this.icon = iconParam instanceof String ? iconParam.toString() : null;
54 Object severityParam = module.getConfiguration().get(PARAM_SEVERITY);
55 this.severity = severityParam instanceof String ? severityParam.toString() : null;