]> git.basschouten.com Git - openhab-addons.git/blob
8bddcb4bbfd9b4c495671c6ea486dd3922a69906
[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.zoneminder.internal.action;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.zoneminder.internal.handler.ZmMonitorHandler;
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  * The {@link ZmActions} defines the thing actions provided by this binding.
28  *
29  * @author Mark Hilbush - Initial contribution
30  */
31 @ThingActionsScope(name = "zoneminder")
32 @NonNullByDefault
33 public class ZmActions implements ThingActions {
34     private final Logger logger = LoggerFactory.getLogger(ZmActions.class);
35
36     private @Nullable ZmMonitorHandler handler;
37
38     @Override
39     public @Nullable ThingHandler getThingHandler() {
40         return handler;
41     }
42
43     @Override
44     public void setThingHandler(@Nullable ThingHandler handler) {
45         if (handler instanceof ZmMonitorHandler zmMonitorHandler) {
46             this.handler = zmMonitorHandler;
47         }
48     }
49
50     /**
51      * The Trigger Alarm function triggers an alarm that will run for the number of seconds
52      * specified by the supplied parameter duration.
53      */
54     @RuleAction(label = "trigger an alarm", description = "Trigger an alarm on the monitor.")
55     public void triggerAlarm(
56             @ActionInput(name = "duration", description = "The duration of the alarm in seconds.") @Nullable Number duration) {
57         logger.debug("ZmActions: Action 'TriggerAlarm' called");
58         ZmMonitorHandler localHandler = handler;
59         if (localHandler == null) {
60             logger.warn("ZmActions: Action service ThingHandler is null!");
61             return;
62         }
63         localHandler.actionTriggerAlarm(duration);
64     }
65
66     public static void triggerAlarm(ThingActions actions, @Nullable Number alarmDuration) {
67         ((ZmActions) actions).triggerAlarm(alarmDuration);
68     }
69
70     /**
71      * The Trigger Alarm function triggers an alarm that will run for the number of seconds
72      * specified in the thing configuration.
73      */
74     @RuleAction(label = "trigger an alarm", description = "Trigger an alarm on the monitor.")
75     public void triggerAlarm() {
76         logger.debug("ZmActions: Action 'TriggerAlarm' called");
77         ZmMonitorHandler localHandler = handler;
78         if (localHandler == null) {
79             logger.warn("ZmActions: Action service ThingHandler is null!");
80             return;
81         }
82         localHandler.actionTriggerAlarm();
83     }
84
85     public static void triggerAlarm(ThingActions actions) {
86         ((ZmActions) actions).triggerAlarm();
87     }
88
89     /**
90      * The Cancel Alarm function cancels a running alarm.
91      */
92     @RuleAction(label = "cancel a running alarm", description = "Cancel a running alarm.")
93     public void cancelAlarm() {
94         logger.debug("ZmActions: Action 'CancelAlarm' called");
95         ZmMonitorHandler localHandler = handler;
96         if (localHandler == null) {
97             logger.warn("ZmActions: Action service ThingHandler is null!");
98             return;
99         }
100         localHandler.actionCancelAlarm();
101     }
102
103     public static void cancelAlarm(ThingActions actions) {
104         ((ZmActions) actions).cancelAlarm();
105     }
106 }