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.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;
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 CaddxPanelActions implements ThingActions {
35 private final Logger logger = LoggerFactory.getLogger(CaddxPanelActions.class);
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.";
41 private @Nullable ThingHandlerPanel handler;
44 public void setThingHandler(@Nullable ThingHandler handler) {
45 if (handler instanceof ThingHandlerPanel panelHandler) {
46 this.handler = panelHandler;
51 public @Nullable ThingHandler getThingHandler() {
55 // Valid are only 4 or 6 digit pins
56 private @Nullable String adjustPin(@Nullable String pin) {
58 logger.debug(PIN_IS_NULL);
62 if (!pin.matches("^\\d{4,4}|\\d{6,6}$")) {
63 logger.debug(PIN_IS_INVALID, pin);
67 return (pin.length() == 4) ? pin + "00" : pin;
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);
79 String adjustedPin = adjustPin(pin);
80 if (adjustedPin == null) {
84 handler.turnOffAnySounderOrAlarm(adjustedPin);
87 public static void turnOffAnySounderOrAlarmOnPanel(ThingActions actions, @Nullable String pin) {
88 ((CaddxPanelActions) actions).turnOffAnySounderOrAlarmOnPanel(pin);
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);
100 String adjustedPin = adjustPin(pin);
101 if (adjustedPin == null) {
105 handler.disarm(adjustedPin);
108 public static void disarmOnPanel(ThingActions actions, @Nullable String pin) {
109 ((CaddxPanelActions) actions).disarmOnPanel(pin);
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);
121 String adjustedPin = adjustPin(pin);
122 if (adjustedPin == null) {
126 handler.armInAwayMode(adjustedPin);
129 public static void armInAwayModeOnPanel(ThingActions actions, @Nullable String pin) {
130 ((CaddxPanelActions) actions).armInAwayModeOnPanel(pin);
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);
142 String adjustedPin = adjustPin(pin);
143 if (adjustedPin == null) {
147 handler.armInStayMode(adjustedPin);
150 public static void armInStayModeOnPanel(ThingActions actions, @Nullable String pin) {
151 ((CaddxPanelActions) actions).armInStayModeOnPanel(pin);
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);
163 String adjustedPin = adjustPin(pin);
164 if (adjustedPin == null) {
168 handler.cancel(adjustedPin);
171 public static void cancelOnPanel(ThingActions actions, @Nullable String pin) {
172 ((CaddxPanelActions) actions).cancelOnPanel(pin);
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);
184 String adjustedPin = adjustPin(pin);
185 if (adjustedPin == null) {
189 handler.initiateAutoArm(adjustedPin);
192 public static void initiateAutoArmOnPanel(ThingActions actions, @Nullable String pin) {
193 ((CaddxPanelActions) actions).initiateAutoArmOnPanel(pin);
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);
205 String adjustedPin = adjustPin(pin);
206 if (adjustedPin == null) {
210 handler.startWalkTestMode(adjustedPin);
213 public static void startWalkTestModeOnPanel(ThingActions actions, @Nullable String pin) {
214 ((CaddxPanelActions) actions).startWalkTestModeOnPanel(pin);
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);
226 String adjustedPin = adjustPin(pin);
227 if (adjustedPin == null) {
231 handler.stopWalkTestMode(adjustedPin);
234 public static void stopWalkTestModeOnPanel(ThingActions actions, @Nullable String pin) {
235 ((CaddxPanelActions) actions).stopWalkTestModeOnPanel(pin);
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);
249 public static void stayOnPanel(ThingActions actions) {
250 ((CaddxPanelActions) actions).stayOnPanel();
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);
264 public static void chimeOnPanel(ThingActions actions) {
265 ((CaddxPanelActions) actions).chimeOnPanel();
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);
279 public static void exitOnPanel(ThingActions actions) {
280 ((CaddxPanelActions) actions).exitOnPanel();
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);
291 handler.bypassInteriors();
294 public static void bypassInteriorsOnPanel(ThingActions actions) {
295 ((CaddxPanelActions) actions).bypassInteriorsOnPanel();
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);
309 public static void firePanicOnPanel(ThingActions actions) {
310 ((CaddxPanelActions) actions).firePanicOnPanel();
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);
321 handler.medicalPanic();
324 public static void medicalPanicOnPanel(ThingActions actions) {
325 ((CaddxPanelActions) actions).medicalPanicOnPanel();
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);
336 handler.policePanic();
339 public static void policePanicOnPanel(ThingActions actions) {
340 ((CaddxPanelActions) actions).policePanicOnPanel();
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);
351 handler.smokeDetectorReset();
354 public static void smokeDetectorResetOnPanel(ThingActions actions) {
355 ((CaddxPanelActions) actions).smokeDetectorResetOnPanel();
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);
366 handler.autoCallbackDownload();
369 public static void autoCallbackDownloadOnPanel(ThingActions actions) {
370 ((CaddxPanelActions) actions).autoCallbackDownloadOnPanel();
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);
381 handler.manualPickupDownload();
384 public static void manualPickupDownloadOnPanel(ThingActions actions) {
385 ((CaddxPanelActions) actions).manualPickupDownloadOnPanel();
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);
396 handler.enableSilentExit();
399 public static void enableSilentExitOnPanel(ThingActions actions) {
400 ((CaddxPanelActions) actions).enableSilentExitOnPanel();
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);
411 handler.performTest();
414 public static void performTestOnPanel(ThingActions actions) {
415 ((CaddxPanelActions) actions).performTestOnPanel();
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);
426 handler.groupBypass();
429 public static void groupBypassOnPanel(ThingActions actions) {
430 ((CaddxPanelActions) actions).groupBypassOnPanel();
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);
441 handler.auxiliaryFunction1();
444 public static void auxiliaryFunction1OnPanel(ThingActions actions) {
445 ((CaddxPanelActions) actions).auxiliaryFunction1OnPanel();
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);
456 handler.auxiliaryFunction2();
459 public static void auxiliaryFunction2OnPanel(ThingActions actions) {
460 ((CaddxPanelActions) actions).auxiliaryFunction2OnPanel();
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);
471 handler.startKeypadSounder();
474 public static void startKeypadSounderOnPanel(ThingActions actions) {
475 ((CaddxPanelActions) actions).startKeypadSounderOnPanel();