]> git.basschouten.com Git - openhab-addons.git/blob
fb1c48d96a2bd4dc3cea3e0468c2ed5600d5938a
[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.caddx.internal.action;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.caddx.internal.handler.ThingHandlerPartition;
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;
25
26 /**
27  * This is the automation engine action handler service for the
28  * caddx bridge actions.
29  *
30  * @author Georgios Moutsos - Initial contribution
31  */
32 @ThingActionsScope(name = "caddx")
33 @NonNullByDefault
34 public class CaddxPartitionActions implements ThingActions {
35     private final Logger logger = LoggerFactory.getLogger(CaddxPartitionActions.class);
36
37     private static final String HANDLER_IS_NULL = "ThingHandlerPartition is null!";
38
39     private @Nullable ThingHandlerPartition handler;
40
41     @Override
42     public void setThingHandler(@Nullable ThingHandler handler) {
43         if (handler instanceof ThingHandlerPartition partitionHandler) {
44             this.handler = partitionHandler;
45         }
46     }
47
48     @Override
49     public @Nullable ThingHandler getThingHandler() {
50         return this.handler;
51     }
52
53     // Valid are only 4 or 6 digit pins
54     private @Nullable String adjustPin(@Nullable String pin) {
55         if (pin == null) {
56             logger.debug("Skipping command due to null value for pin.");
57             return null;
58         }
59
60         if (!pin.matches("^\\d{4,4}|\\d{6,6}$")) {
61             logger.debug("Skipping command due to invalid value for pin. {}", pin);
62             return null;
63         }
64
65         return (pin.length() == 4) ? pin + "00" : pin;
66     }
67
68     @RuleAction(label = "turnOffAnySounderOrAlarm", description = "Turn off any sounder or alarm")
69     public void turnOffAnySounderOrAlarm(
70             @ActionInput(name = "pin", label = "pin", description = "The pin 4 or 6 digit pin") @Nullable String pin) {
71         ThingHandlerPartition handler = this.handler;
72         if (handler == null) {
73             logger.debug(HANDLER_IS_NULL);
74             return;
75         }
76
77         String adjustedPin = adjustPin(pin);
78         if (adjustedPin == null) {
79             return;
80         }
81
82         handler.turnOffAnySounderOrAlarm(adjustedPin);
83     }
84
85     public static void turnOffAnySounderOrAlarm(ThingActions actions, @Nullable String pin) {
86         ((CaddxPartitionActions) actions).turnOffAnySounderOrAlarm(pin);
87     }
88
89     @RuleAction(label = "disarm", description = "Dis-arm")
90     public void disarm(
91             @ActionInput(name = "pin", label = "pin", description = "The pin 4 or 6 digit pin") @Nullable String pin) {
92         ThingHandlerPartition handler = this.handler;
93         if (handler == null) {
94             logger.debug(HANDLER_IS_NULL);
95             return;
96         }
97
98         String adjustedPin = adjustPin(pin);
99         if (adjustedPin == null) {
100             return;
101         }
102
103         handler.disarm(adjustedPin);
104     }
105
106     public static void disarm(ThingActions actions, @Nullable String pin) {
107         ((CaddxPartitionActions) actions).disarm(pin);
108     }
109
110     @RuleAction(label = "armInAwayMode", description = "Arm in away mode")
111     public void armInAwayMode(
112             @ActionInput(name = "pin", label = "pin", description = "The pin 4 or 6 digit pin") @Nullable String pin) {
113         ThingHandlerPartition handler = this.handler;
114         if (handler == null) {
115             logger.debug(HANDLER_IS_NULL);
116             return;
117         }
118
119         String adjustedPin = adjustPin(pin);
120         if (adjustedPin == null) {
121             return;
122         }
123
124         handler.armInAwayMode(adjustedPin);
125     }
126
127     public static void armInAwayMode(ThingActions actions, @Nullable String pin) {
128         ((CaddxPartitionActions) actions).armInAwayMode(pin);
129     }
130
131     @RuleAction(label = "armInStayMode", description = "Arm in stay mode")
132     public void armInStayMode(
133             @ActionInput(name = "pin", label = "pin", description = "The pin 4 or 6 digit pin") @Nullable String pin) {
134         ThingHandlerPartition handler = this.handler;
135         if (handler == null) {
136             logger.debug(HANDLER_IS_NULL);
137             return;
138         }
139
140         String adjustedPin = adjustPin(pin);
141         if (adjustedPin == null) {
142             return;
143         }
144
145         handler.armInStayMode(adjustedPin);
146     }
147
148     public static void armInStayMode(ThingActions actions, @Nullable String pin) {
149         ((CaddxPartitionActions) actions).armInStayMode(pin);
150     }
151
152     @RuleAction(label = "cancel", description = "Cancel")
153     public void cancel(
154             @ActionInput(name = "pin", label = "pin", description = "The pin 4 or 6 digit pin") @Nullable String pin) {
155         ThingHandlerPartition handler = this.handler;
156         if (handler == null) {
157             logger.debug(HANDLER_IS_NULL);
158             return;
159         }
160
161         String adjustedPin = adjustPin(pin);
162         if (adjustedPin == null) {
163             return;
164         }
165
166         handler.cancel(adjustedPin);
167     }
168
169     public static void cancel(ThingActions actions, @Nullable String pin) {
170         ((CaddxPartitionActions) actions).cancel(pin);
171     }
172
173     @RuleAction(label = "initiateAutoArm", description = "Initiate auto arm")
174     public void initiateAutoArm(
175             @ActionInput(name = "pin", label = "pin", description = "The pin 4 or 6 digit pin") @Nullable String pin) {
176         ThingHandlerPartition handler = this.handler;
177         if (handler == null) {
178             logger.debug(HANDLER_IS_NULL);
179             return;
180         }
181
182         String adjustedPin = adjustPin(pin);
183         if (adjustedPin == null) {
184             return;
185         }
186
187         handler.initiateAutoArm(adjustedPin);
188     }
189
190     public static void initiateAutoArm(ThingActions actions, @Nullable String pin) {
191         ((CaddxPartitionActions) actions).initiateAutoArm(pin);
192     }
193
194     @RuleAction(label = "startWalkTestMode", description = "Start walk-test mode")
195     public void startWalkTestMode(
196             @ActionInput(name = "pin", label = "pin", description = "The pin 4 or 6 digit pin") @Nullable String pin) {
197         ThingHandlerPartition handler = this.handler;
198         if (handler == null) {
199             logger.debug(HANDLER_IS_NULL);
200             return;
201         }
202
203         String adjustedPin = adjustPin(pin);
204         if (adjustedPin == null) {
205             return;
206         }
207
208         handler.startWalkTestMode(adjustedPin);
209     }
210
211     public static void startWalkTestMode(ThingActions actions, @Nullable String pin) {
212         ((CaddxPartitionActions) actions).startWalkTestMode(pin);
213     }
214
215     @RuleAction(label = "stopWalkTestMode", description = "Stop walk-test mode")
216     public void stopWalkTestMode(
217             @ActionInput(name = "pin", label = "pin", description = "The pin 4 or 6 digit pin") @Nullable String pin) {
218         ThingHandlerPartition handler = this.handler;
219         if (handler == null) {
220             logger.debug(HANDLER_IS_NULL);
221             return;
222         }
223
224         String adjustedPin = adjustPin(pin);
225         if (adjustedPin == null) {
226             return;
227         }
228
229         handler.stopWalkTestMode(adjustedPin);
230     }
231
232     public static void stopWalkTestMode(ThingActions actions, @Nullable String pin) {
233         ((CaddxPartitionActions) actions).stopWalkTestMode(pin);
234     }
235
236     @RuleAction(label = "stay", description = "Stay (1 button arm / toggle interiors)")
237     public void stay() {
238         ThingHandlerPartition handler = this.handler;
239         if (handler == null) {
240             logger.debug(HANDLER_IS_NULL);
241             return;
242         }
243
244         handler.stay();
245     }
246
247     public static void stay(ThingActions actions) {
248         ((CaddxPartitionActions) actions).stay();
249     }
250
251     @RuleAction(label = "chime", description = "Chime (toggle chime mode)")
252     public void chime() {
253         ThingHandlerPartition handler = this.handler;
254         if (handler == null) {
255             logger.debug(HANDLER_IS_NULL);
256             return;
257         }
258
259         handler.chime();
260     }
261
262     public static void chime(ThingActions actions) {
263         ((CaddxPartitionActions) actions).chime();
264     }
265
266     @RuleAction(label = "exit", description = "Exit (1 button arm / toggle instant)")
267     public void exit() {
268         ThingHandlerPartition handler = this.handler;
269         if (handler == null) {
270             logger.debug(HANDLER_IS_NULL);
271             return;
272         }
273
274         handler.exit();
275     }
276
277     public static void exit(ThingActions actions) {
278         ((CaddxPartitionActions) actions).exit();
279     }
280
281     @RuleAction(label = "bypassInteriors", description = "Bypass Interiors")
282     public void bypassInteriors() {
283         ThingHandlerPartition handler = this.handler;
284         if (handler == null) {
285             logger.debug(HANDLER_IS_NULL);
286             return;
287         }
288
289         handler.bypassInteriors();
290     }
291
292     public static void bypassInteriors(ThingActions actions) {
293         ((CaddxPartitionActions) actions).bypassInteriors();
294     }
295
296     @RuleAction(label = "firePanic", description = "Fire Panic")
297     public void firePanic() {
298         ThingHandlerPartition handler = this.handler;
299         if (handler == null) {
300             logger.debug(HANDLER_IS_NULL);
301             return;
302         }
303
304         handler.firePanic();
305     }
306
307     public static void firePanic(ThingActions actions) {
308         ((CaddxPartitionActions) actions).firePanic();
309     }
310
311     @RuleAction(label = "medicalPanic", description = "Medical Panic")
312     public void medicalPanic() {
313         ThingHandlerPartition handler = this.handler;
314         if (handler == null) {
315             logger.debug(HANDLER_IS_NULL);
316             return;
317         }
318
319         handler.medicalPanic();
320     }
321
322     public static void medicalPanic(ThingActions actions) {
323         ((CaddxPartitionActions) actions).medicalPanic();
324     }
325
326     @RuleAction(label = "policePanic", description = "Police Panic")
327     public void policePanic() {
328         ThingHandlerPartition handler = this.handler;
329         if (handler == null) {
330             logger.debug(HANDLER_IS_NULL);
331             return;
332         }
333
334         handler.policePanic();
335     }
336
337     public static void policePanic(ThingActions actions) {
338         ((CaddxPartitionActions) actions).policePanic();
339     }
340
341     @RuleAction(label = "smokeDetectorReset", description = "Smoke detector reset")
342     public void smokeDetectorReset() {
343         ThingHandlerPartition handler = this.handler;
344         if (handler == null) {
345             logger.debug(HANDLER_IS_NULL);
346             return;
347         }
348
349         handler.smokeDetectorReset();
350     }
351
352     public static void smokeDetectorReset(ThingActions actions) {
353         ((CaddxPartitionActions) actions).smokeDetectorReset();
354     }
355
356     @RuleAction(label = "autoCallbackDownload", description = "Auto callback download")
357     public void autoCallbackDownload() {
358         ThingHandlerPartition handler = this.handler;
359         if (handler == null) {
360             logger.debug(HANDLER_IS_NULL);
361             return;
362         }
363
364         handler.autoCallbackDownload();
365     }
366
367     public static void autoCallbackDownload(ThingActions actions) {
368         ((CaddxPartitionActions) actions).autoCallbackDownload();
369     }
370
371     @RuleAction(label = "manualPickupDownload", description = "Manual pickup download")
372     public void manualPickupDownload() {
373         ThingHandlerPartition handler = this.handler;
374         if (handler == null) {
375             logger.debug(HANDLER_IS_NULL);
376             return;
377         }
378
379         handler.manualPickupDownload();
380     }
381
382     public static void manualPickupDownload(ThingActions actions) {
383         ((CaddxPartitionActions) actions).manualPickupDownload();
384     }
385
386     @RuleAction(label = "enableSilentExit", description = "Enable silent exit")
387     public void enableSilentExit() {
388         ThingHandlerPartition handler = this.handler;
389         if (handler == null) {
390             logger.debug(HANDLER_IS_NULL);
391             return;
392         }
393
394         handler.enableSilentExit();
395     }
396
397     public static void enableSilentExit(ThingActions actions) {
398         ((CaddxPartitionActions) actions).enableSilentExit();
399     }
400
401     @RuleAction(label = "performTest", description = "Perform test")
402     public void performTest() {
403         ThingHandlerPartition handler = this.handler;
404         if (handler == null) {
405             logger.debug(HANDLER_IS_NULL);
406             return;
407         }
408
409         handler.performTest();
410     }
411
412     public static void performTest(ThingActions actions) {
413         ((CaddxPartitionActions) actions).performTest();
414     }
415
416     @RuleAction(label = "groupBypass", description = "Group Bypass")
417     public void groupBypass() {
418         ThingHandlerPartition handler = this.handler;
419         if (handler == null) {
420             logger.debug(HANDLER_IS_NULL);
421             return;
422         }
423
424         handler.groupBypass();
425     }
426
427     public static void groupBypass(ThingActions actions) {
428         ((CaddxPartitionActions) actions).groupBypass();
429     }
430
431     @RuleAction(label = "auxiliaryFunction1", description = "Auxiliary Function 1")
432     public void auxiliaryFunction1() {
433         ThingHandlerPartition handler = this.handler;
434         if (handler == null) {
435             logger.debug(HANDLER_IS_NULL);
436             return;
437         }
438
439         handler.auxiliaryFunction1();
440     }
441
442     public static void auxiliaryFunction1(ThingActions actions) {
443         ((CaddxPartitionActions) actions).auxiliaryFunction1();
444     }
445
446     @RuleAction(label = "auxiliaryFunction2", description = "Auxiliary Function 2")
447     public void auxiliaryFunction2() {
448         ThingHandlerPartition handler = this.handler;
449         if (handler == null) {
450             logger.debug(HANDLER_IS_NULL);
451             return;
452         }
453
454         handler.auxiliaryFunction2();
455     }
456
457     public static void auxiliaryFunction2(ThingActions actions) {
458         ((CaddxPartitionActions) actions).auxiliaryFunction2();
459     }
460
461     @RuleAction(label = "startKeypadSounder", description = "Start keypad sounder")
462     public void startKeypadSounder() {
463         ThingHandlerPartition handler = this.handler;
464         if (handler == null) {
465             logger.debug(HANDLER_IS_NULL);
466             return;
467         }
468
469         handler.startKeypadSounder();
470     }
471
472     public static void startKeypadSounder(ThingActions actions) {
473         ((CaddxPartitionActions) actions).startKeypadSounder();
474     }
475 }