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.caddx.internal.action;
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;
27 * This is the automation engine action handler service for the
28 * caddx bridge actions.
30 * @author Georgios Moutsos - Initial contribution
32 @ThingActionsScope(name = "caddx")
34 public class CaddxPartitionActions implements ThingActions {
35 private final Logger logger = LoggerFactory.getLogger(CaddxPartitionActions.class);
37 private static final String HANDLER_IS_NULL = "ThingHandlerPartition is null!";
39 private @Nullable ThingHandlerPartition handler;
42 public void setThingHandler(@Nullable ThingHandler handler) {
43 if (handler instanceof ThingHandlerPartition partitionHandler) {
44 this.handler = partitionHandler;
49 public @Nullable ThingHandler getThingHandler() {
53 // Valid are only 4 or 6 digit pins
54 private @Nullable String adjustPin(@Nullable String pin) {
56 logger.debug("Skipping command due to null value for pin.");
60 if (!pin.matches("^\\d{4,4}|\\d{6,6}$")) {
61 logger.debug("Skipping command due to invalid value for pin. {}", pin);
65 return (pin.length() == 4) ? pin + "00" : pin;
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);
77 String adjustedPin = adjustPin(pin);
78 if (adjustedPin == null) {
82 handler.turnOffAnySounderOrAlarm(adjustedPin);
85 public static void turnOffAnySounderOrAlarm(ThingActions actions, @Nullable String pin) {
86 ((CaddxPartitionActions) actions).turnOffAnySounderOrAlarm(pin);
89 @RuleAction(label = "disarm", description = "Dis-arm")
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);
98 String adjustedPin = adjustPin(pin);
99 if (adjustedPin == null) {
103 handler.disarm(adjustedPin);
106 public static void disarm(ThingActions actions, @Nullable String pin) {
107 ((CaddxPartitionActions) actions).disarm(pin);
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);
119 String adjustedPin = adjustPin(pin);
120 if (adjustedPin == null) {
124 handler.armInAwayMode(adjustedPin);
127 public static void armInAwayMode(ThingActions actions, @Nullable String pin) {
128 ((CaddxPartitionActions) actions).armInAwayMode(pin);
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);
140 String adjustedPin = adjustPin(pin);
141 if (adjustedPin == null) {
145 handler.armInStayMode(adjustedPin);
148 public static void armInStayMode(ThingActions actions, @Nullable String pin) {
149 ((CaddxPartitionActions) actions).armInStayMode(pin);
152 @RuleAction(label = "cancel", description = "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);
161 String adjustedPin = adjustPin(pin);
162 if (adjustedPin == null) {
166 handler.cancel(adjustedPin);
169 public static void cancel(ThingActions actions, @Nullable String pin) {
170 ((CaddxPartitionActions) actions).cancel(pin);
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);
182 String adjustedPin = adjustPin(pin);
183 if (adjustedPin == null) {
187 handler.initiateAutoArm(adjustedPin);
190 public static void initiateAutoArm(ThingActions actions, @Nullable String pin) {
191 ((CaddxPartitionActions) actions).initiateAutoArm(pin);
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);
203 String adjustedPin = adjustPin(pin);
204 if (adjustedPin == null) {
208 handler.startWalkTestMode(adjustedPin);
211 public static void startWalkTestMode(ThingActions actions, @Nullable String pin) {
212 ((CaddxPartitionActions) actions).startWalkTestMode(pin);
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);
224 String adjustedPin = adjustPin(pin);
225 if (adjustedPin == null) {
229 handler.stopWalkTestMode(adjustedPin);
232 public static void stopWalkTestMode(ThingActions actions, @Nullable String pin) {
233 ((CaddxPartitionActions) actions).stopWalkTestMode(pin);
236 @RuleAction(label = "stay", description = "Stay (1 button arm / toggle interiors)")
238 ThingHandlerPartition handler = this.handler;
239 if (handler == null) {
240 logger.debug(HANDLER_IS_NULL);
247 public static void stay(ThingActions actions) {
248 ((CaddxPartitionActions) actions).stay();
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);
262 public static void chime(ThingActions actions) {
263 ((CaddxPartitionActions) actions).chime();
266 @RuleAction(label = "exit", description = "Exit (1 button arm / toggle instant)")
268 ThingHandlerPartition handler = this.handler;
269 if (handler == null) {
270 logger.debug(HANDLER_IS_NULL);
277 public static void exit(ThingActions actions) {
278 ((CaddxPartitionActions) actions).exit();
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);
289 handler.bypassInteriors();
292 public static void bypassInteriors(ThingActions actions) {
293 ((CaddxPartitionActions) actions).bypassInteriors();
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);
307 public static void firePanic(ThingActions actions) {
308 ((CaddxPartitionActions) actions).firePanic();
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);
319 handler.medicalPanic();
322 public static void medicalPanic(ThingActions actions) {
323 ((CaddxPartitionActions) actions).medicalPanic();
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);
334 handler.policePanic();
337 public static void policePanic(ThingActions actions) {
338 ((CaddxPartitionActions) actions).policePanic();
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);
349 handler.smokeDetectorReset();
352 public static void smokeDetectorReset(ThingActions actions) {
353 ((CaddxPartitionActions) actions).smokeDetectorReset();
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);
364 handler.autoCallbackDownload();
367 public static void autoCallbackDownload(ThingActions actions) {
368 ((CaddxPartitionActions) actions).autoCallbackDownload();
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);
379 handler.manualPickupDownload();
382 public static void manualPickupDownload(ThingActions actions) {
383 ((CaddxPartitionActions) actions).manualPickupDownload();
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);
394 handler.enableSilentExit();
397 public static void enableSilentExit(ThingActions actions) {
398 ((CaddxPartitionActions) actions).enableSilentExit();
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);
409 handler.performTest();
412 public static void performTest(ThingActions actions) {
413 ((CaddxPartitionActions) actions).performTest();
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);
424 handler.groupBypass();
427 public static void groupBypass(ThingActions actions) {
428 ((CaddxPartitionActions) actions).groupBypass();
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);
439 handler.auxiliaryFunction1();
442 public static void auxiliaryFunction1(ThingActions actions) {
443 ((CaddxPartitionActions) actions).auxiliaryFunction1();
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);
454 handler.auxiliaryFunction2();
457 public static void auxiliaryFunction2(ThingActions actions) {
458 ((CaddxPartitionActions) actions).auxiliaryFunction2();
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);
469 handler.startKeypadSounder();
472 public static void startKeypadSounder(ThingActions actions) {
473 ((CaddxPartitionActions) actions).startKeypadSounder();