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.enigma2.internal.actions;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.enigma2.internal.Enigma2BindingConstants;
18 import org.openhab.binding.enigma2.internal.handler.Enigma2Handler;
19 import org.openhab.core.automation.annotation.ActionInput;
20 import org.openhab.core.automation.annotation.RuleAction;
21 import org.openhab.core.thing.binding.ThingActions;
22 import org.openhab.core.thing.binding.ThingActionsScope;
23 import org.openhab.core.thing.binding.ThingHandler;
26 * This is the automation engine actions handler service for the
29 * @author Guido Dolfen - Initial contribution
31 @ThingActionsScope(name = "enigma2")
33 public class Enigma2Actions implements ThingActions {
34 private @Nullable Enigma2Handler handler;
37 public void setThingHandler(@Nullable ThingHandler handler) {
38 this.handler = (Enigma2Handler) handler;
42 public @Nullable Enigma2Handler getThingHandler() {
46 @RuleAction(label = "@text/actions.enigma2.send-rc-button.label", description = "@text/actions.enigma2.send-rc-button.description")
47 @SuppressWarnings("null")
48 public void sendRcCommand(
49 @ActionInput(name = "rcButton", label = "@text/actions-input.enigma2.rc-button.label", description = "@text/actions-input.enigma2.rc-button.description") String rcButton) {
50 handler.sendRcCommand(rcButton);
53 @RuleAction(label = "@text/actions.enigma2.send-info.label", description = "@text/actions.enigma2.send-info.description")
54 @SuppressWarnings("null")
56 @ActionInput(name = "text", label = "@text/actions-input.enigma2.text.label", description = "@text/actions-input.enigma2.text.description") String text) {
57 handler.sendInfo(Enigma2BindingConstants.MESSAGE_TIMEOUT, text);
60 @RuleAction(label = "@text/actions.enigma2.send-info.label", description = "@text/actions.enigma2.send-info.description")
61 @SuppressWarnings("null")
63 @ActionInput(name = "text", label = "@text/actions-input.enigma2.text.label", description = "@text/actions-input.enigma2.text.description") String text,
64 @ActionInput(name = "timeout", label = "@text/actions-input.enigma2.timeout.label", description = "@text/actions-input.enigma2.timeout.description") int timeout) {
65 handler.sendInfo(timeout, text);
68 @RuleAction(label = "@text/actions.enigma2.send-warning.label", description = "@text/actions.enigma2.send-warning.description")
69 @SuppressWarnings("null")
70 public void sendWarning(
71 @ActionInput(name = "text", label = "@text/actions-input.enigma2.text.label", description = "@text/actions-input.enigma2.text.description") String text) {
72 handler.sendWarning(Enigma2BindingConstants.MESSAGE_TIMEOUT, text);
75 @RuleAction(label = "@text/actions.enigma2.send-warning.label", description = "@text/actions.enigma2.send-warning.description")
76 @SuppressWarnings("null")
77 public void sendWarning(
78 @ActionInput(name = "text", label = "@text/actions-input.enigma2.text.label", description = "@text/actions-input.enigma2.text.description") String text,
79 @ActionInput(name = "timeout", label = "@text/actions-input.enigma2.timeout.label", description = "@text/actions-input.enigma2.timeout.description") int timeout) {
80 handler.sendWarning(timeout, text);
83 @RuleAction(label = "@text/actions.enigma2.send-error.label", description = "@text/actions.enigma2.send-error.description")
84 @SuppressWarnings("null")
85 public void sendError(
86 @ActionInput(name = "text", label = "@text/actions-input.enigma2.text.label", description = "@text/actions-input.enigma2.text.description") String text) {
87 handler.sendError(Enigma2BindingConstants.MESSAGE_TIMEOUT, text);
90 @RuleAction(label = "@text/actions.enigma2.send-error.label", description = "@text/actions.enigma2.send-error.description")
91 @SuppressWarnings("null")
92 public void sendError(
93 @ActionInput(name = "text", label = "@text/actions-input.enigma2.text.label", description = "@text/actions-input.enigma2.text.description") String text,
94 @ActionInput(name = "timeout", label = "@text/actions-input.enigma2.timeout.label", description = "@text/actions-input.enigma2.timeout.description") int timeout) {
95 handler.sendError(timeout, text);
98 @RuleAction(label = "@text/actions.enigma2.send-error.label", description = "@text/actions.enigma2.send-question.description")
99 @SuppressWarnings("null")
100 public void sendQuestion(
101 @ActionInput(name = "text", label = "@text/actions-input.enigma2.text.label", description = "@text/actions-input.enigma2.text.description") String text) {
102 handler.sendQuestion(Enigma2BindingConstants.MESSAGE_TIMEOUT, text);
105 @RuleAction(label = "@text/actions.enigma2.send-error.label", description = "@text/actions.enigma2.send-question.description")
106 @SuppressWarnings("null")
107 public void sendQuestion(
108 @ActionInput(name = "text", label = "@text/actions-input.enigma2.text.label", description = "@text/actions-input.enigma2.text.description") String text,
109 @ActionInput(name = "timeout", label = "@text/actions-input.enigma2.timeout.label", description = "@text/actions-input.enigma2.timeout.description") int timeout) {
110 handler.sendQuestion(timeout, text);
113 // delegation methods for "legacy" rule support
114 public static void sendRcCommand(ThingActions actions, String rcButton) {
115 ((Enigma2Actions) actions).sendRcCommand(rcButton);
118 public static void sendInfo(ThingActions actions, String info) {
119 ((Enigma2Actions) actions).sendInfo(info);
122 public static void sendInfo(ThingActions actions, String info, int timeout) {
123 ((Enigma2Actions) actions).sendInfo(info, timeout);
126 public static void sendWarning(ThingActions actions, String warning) {
127 ((Enigma2Actions) actions).sendWarning(warning);
130 public static void sendWarning(ThingActions actions, String warning, int timeout) {
131 ((Enigma2Actions) actions).sendWarning(warning, timeout);
134 public static void sendError(ThingActions actions, String error) {
135 ((Enigma2Actions) actions).sendError(error);
138 public static void sendError(ThingActions actions, String error, int timeout) {
139 ((Enigma2Actions) actions).sendError(error, timeout);
142 public static void sendQuestion(ThingActions actions, String text) {
143 ((Enigma2Actions) actions).sendQuestion(text);
146 public static void sendQuestion(ThingActions actions, String text, int timeout) {
147 ((Enigma2Actions) actions).sendQuestion(text, timeout);