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.binding.prowl.internal.action;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.prowl.internal.ProwlHandler;
18 import org.openhab.core.automation.annotation.ActionInput;
19 import org.openhab.core.automation.annotation.RuleAction;
20 import org.openhab.core.thing.binding.ThingActions;
21 import org.openhab.core.thing.binding.ThingActionsScope;
22 import org.openhab.core.thing.binding.ThingHandler;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * The {@link ProwlActions} class contains methods for use in DSL.
29 * @author Ondrej Pecta - Initial contribution
31 @ThingActionsScope(name = "prowl")
33 public class ProwlActions implements ThingActions {
34 private final Logger logger = LoggerFactory.getLogger(ProwlActions.class);
35 private @Nullable ProwlHandler handler;
38 public void setThingHandler(ThingHandler thingHandler) {
39 this.handler = (ProwlHandler) thingHandler;
43 public @Nullable ThingHandler getThingHandler() {
47 @RuleAction(label = "@text/pushNotificationActionLabel", description = "@text/pushNotificationActionDescription")
48 public void pushNotification(
49 @ActionInput(name = "event", label = "@text/pushNotificationActionEventLabel", description = "@text/pushNotificationActionEventDescription") @Nullable String event,
50 @ActionInput(name = "message", label = "@text/pushNotificationActionMessageLabel", description = "@text/pushNotificationActionMessageDescription") @Nullable String message) {
51 ProwlHandler clientHandler = handler;
52 if (clientHandler == null) {
53 logger.warn("Prowl ThingHandler is null");
57 handler.pushNotification(event, message);
60 @RuleAction(label = "@text/pushNotificationActionLabel", description = "@text/pushNotificationActionDescription")
61 public void pushNotification(
62 @ActionInput(name = "event", label = "@text/pushNotificationActionEventLabel", description = "@text/pushNotificationActionEventDescription") @Nullable String event,
63 @ActionInput(name = "message", label = "@text/pushNotificationActionMessageLabel", description = "@text/pushNotificationActionMessageDescription") @Nullable String message,
64 @ActionInput(name = "priority", label = "@text/pushNotificationActionPriorityLabel", description = "@text/pushNotificationActionPriorityDescription") int priority) {
65 ProwlHandler clientHandler = handler;
66 if (clientHandler == null) {
67 logger.warn("Prowl ThingHandler is null");
71 handler.pushNotification(event, message, priority);
74 public static void pushNotification(@Nullable ThingActions actions, @Nullable String event,
75 @Nullable String description) {
76 pushNotification(actions, event, description, 0);
79 public static void pushNotification(@Nullable ThingActions actions, @Nullable String event,
80 @Nullable String description, int priority) {
81 if (actions instanceof ProwlActions prowlActions) {
82 prowlActions.pushNotification(event, description, priority);
84 throw new IllegalArgumentException("Instance is not a ProwlActions class.");