]> git.basschouten.com Git - openhab-addons.git/blob
258fd239d5ae25395392cf5402d094cb8a9fb42d
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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(@Nullable ThingActions actions, String rcButton) {
115         if (actions instanceof Enigma2Actions) {
116             ((Enigma2Actions) actions).sendRcCommand(rcButton);
117         } else {
118             throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
119         }
120     }
121
122     public static void sendInfo(@Nullable ThingActions actions, String info) {
123         if (actions instanceof Enigma2Actions) {
124             ((Enigma2Actions) actions).sendInfo(info);
125         } else {
126             throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
127         }
128     }
129
130     public static void sendInfo(@Nullable ThingActions actions, String info, int timeout) {
131         if (actions instanceof Enigma2Actions) {
132             ((Enigma2Actions) actions).sendInfo(info, timeout);
133         } else {
134             throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
135         }
136     }
137
138     public static void sendWarning(@Nullable ThingActions actions, String warning) {
139         if (actions instanceof Enigma2Actions) {
140             ((Enigma2Actions) actions).sendWarning(warning);
141         } else {
142             throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
143         }
144     }
145
146     public static void sendWarning(@Nullable ThingActions actions, String warning, int timeout) {
147         if (actions instanceof Enigma2Actions) {
148             ((Enigma2Actions) actions).sendWarning(warning, timeout);
149         } else {
150             throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
151         }
152     }
153
154     public static void sendError(@Nullable ThingActions actions, String error) {
155         if (actions instanceof Enigma2Actions) {
156             ((Enigma2Actions) actions).sendError(error);
157         } else {
158             throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
159         }
160     }
161
162     public static void sendError(@Nullable ThingActions actions, String error, int timeout) {
163         if (actions instanceof Enigma2Actions) {
164             ((Enigma2Actions) actions).sendError(error, timeout);
165         } else {
166             throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
167         }
168     }
169
170     public static void sendQuestion(@Nullable ThingActions actions, String text) {
171         if (actions instanceof Enigma2Actions) {
172             ((Enigma2Actions) actions).sendQuestion(text);
173         } else {
174             throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
175         }
176     }
177
178     public static void sendQuestion(@Nullable ThingActions actions, String text, int timeout) {
179         if (actions instanceof Enigma2Actions) {
180             ((Enigma2Actions) actions).sendQuestion(text, timeout);
181         } else {
182             throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
183         }
184     }
185 }