]> git.basschouten.com Git - openhab-addons.git/blob
8b88c1932fc8af2eab0105668a5cceaf8ea1ac5c
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.binding.enigma2.internal.actions;
14
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;
24
25 /**
26  * This is the automation engine actions handler service for the
27  * enigma2 actions.
28  *
29  * @author Guido Dolfen - Initial contribution
30  */
31 @ThingActionsScope(name = "enigma2")
32 @NonNullByDefault
33 public class Enigma2Actions implements ThingActions {
34     private @Nullable Enigma2Handler handler;
35
36     @Override
37     public void setThingHandler(@Nullable ThingHandler handler) {
38         this.handler = (Enigma2Handler) handler;
39     }
40
41     @Override
42     public @Nullable Enigma2Handler getThingHandler() {
43         return handler;
44     }
45
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);
51     }
52
53     @RuleAction(label = "@text/actions.enigma2.send-info.label", description = "@text/actions.enigma2.send-info.description")
54     @SuppressWarnings("null")
55     public void sendInfo(
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);
58     }
59
60     @RuleAction(label = "@text/actions.enigma2.send-info.label", description = "@text/actions.enigma2.send-info.description")
61     @SuppressWarnings("null")
62     public void sendInfo(
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);
66     }
67
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);
73     }
74
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);
81     }
82
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);
88     }
89
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);
96     }
97
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);
103     }
104
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);
111     }
112
113     // delegation methods for "legacy" rule support
114     public static void sendRcCommand(ThingActions actions, String rcButton) {
115         ((Enigma2Actions) actions).sendRcCommand(rcButton);
116     }
117
118     public static void sendInfo(ThingActions actions, String info) {
119         ((Enigma2Actions) actions).sendInfo(info);
120     }
121
122     public static void sendInfo(ThingActions actions, String info, int timeout) {
123         ((Enigma2Actions) actions).sendInfo(info, timeout);
124     }
125
126     public static void sendWarning(ThingActions actions, String warning) {
127         ((Enigma2Actions) actions).sendWarning(warning);
128     }
129
130     public static void sendWarning(ThingActions actions, String warning, int timeout) {
131         ((Enigma2Actions) actions).sendWarning(warning, timeout);
132     }
133
134     public static void sendError(ThingActions actions, String error) {
135         ((Enigma2Actions) actions).sendError(error);
136     }
137
138     public static void sendError(ThingActions actions, String error, int timeout) {
139         ((Enigma2Actions) actions).sendError(error, timeout);
140     }
141
142     public static void sendQuestion(ThingActions actions, String text) {
143         ((Enigma2Actions) actions).sendQuestion(text);
144     }
145
146     public static void sendQuestion(ThingActions actions, String text, int timeout) {
147         ((Enigma2Actions) actions).sendQuestion(text, timeout);
148     }
149 }