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.zoneminder.internal.action;
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;
27 * The {@link ZmActions} defines the thing actions provided by this binding.
29 * @author Mark Hilbush - Initial contribution
31 @ThingActionsScope(name = "zoneminder")
33 public class ZmActions implements ThingActions {
34 private final Logger logger = LoggerFactory.getLogger(ZmActions.class);
36 private @Nullable ZmMonitorHandler handler;
39 public @Nullable ThingHandler getThingHandler() {
44 public void setThingHandler(@Nullable ThingHandler handler) {
45 if (handler instanceof ZmMonitorHandler) {
46 this.handler = (ZmMonitorHandler) handler;
51 * The Trigger Alarm function triggers an alarm that will run for the number of seconds
52 * specified by the supplied parameter duration.
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!");
63 localHandler.actionTriggerAlarm(duration);
66 public static void triggerAlarm(ThingActions actions, @Nullable Number alarmDuration) {
67 ((ZmActions) actions).triggerAlarm(alarmDuration);
71 * The Trigger Alarm function triggers an alarm that will run for the number of seconds
72 * specified in the thing configuration.
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!");
82 localHandler.actionTriggerAlarm();
85 public static void triggerAlarm(ThingActions actions) {
86 ((ZmActions) actions).triggerAlarm();
90 * The Cancel Alarm function cancels a running alarm.
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!");
100 localHandler.actionCancelAlarm();
103 public static void cancelAlarm(ThingActions actions) {
104 ((ZmActions) actions).cancelAlarm();