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