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.doorbird.internal.action;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.doorbird.internal.handler.DoorbellHandler;
18 import org.openhab.core.automation.annotation.ActionOutput;
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 DoorbirdActions} defines rule actions for the doorbird binding.
29 * @author Mark Hilbush - Initial contribution
31 @ThingActionsScope(name = "doorbird")
33 public class DoorbirdActions implements ThingActions {
34 private final Logger logger = LoggerFactory.getLogger(DoorbirdActions.class);
36 private @Nullable DoorbellHandler handler;
38 public DoorbirdActions() {
39 logger.debug("DoorbirdActions service created");
43 public void setThingHandler(@Nullable ThingHandler handler) {
44 if (handler instanceof DoorbellHandler doorbellHandler) {
45 this.handler = doorbellHandler;
50 public @Nullable ThingHandler getThingHandler() {
54 @RuleAction(label = "restart the Doorbird", description = "Restarts the Doorbird device.")
55 public void restart() {
56 logger.debug("Doorbird action 'restart' called");
57 if (handler != null) {
58 handler.actionRestart();
60 logger.info("Doorbird Action service ThingHandler is null!");
64 public static void restart(ThingActions actions) {
65 ((DoorbirdActions) actions).restart();
68 @RuleAction(label = "hangup a SIP call", description = "Hangup SIP call.")
69 public void sipHangup() {
70 logger.debug("Doorbird action 'sipHangup' called");
71 if (handler != null) {
72 handler.actionSIPHangup();
74 logger.info("Doorbird Action service ThingHandler is null!");
78 public static void sipHangup(ThingActions actions) {
79 ((DoorbirdActions) actions).sipHangup();
82 @RuleAction(label = "get the ring time limit", description = "Get the value of RING_TIME_LIMIT.")
83 public @ActionOutput(name = "getRingTimeLimit", type = "java.lang.String") String getRingTimeLimit() {
84 logger.debug("Doorbird action 'getRingTimeLimit' called");
85 if (handler != null) {
86 return handler.actionGetRingTimeLimit();
88 logger.info("Doorbird Action service ThingHandler is null!");
93 public static String getRingTimeLimit(ThingActions actions) {
94 return ((DoorbirdActions) actions).getRingTimeLimit();
97 @RuleAction(label = "get the call time limit", description = "Get the value of CALL_TIME_LIMIT.")
98 public @ActionOutput(name = "getCallTimeLimit", type = "java.lang.String") String getCallTimeLimit() {
99 logger.debug("Doorbird action 'getCallTimeLimit' called");
100 if (handler != null) {
101 return handler.actionGetCallTimeLimit();
103 logger.info("Doorbird Action service ThingHandler is null!");
108 public static String getCallTimeLimit(ThingActions actions) {
109 return ((DoorbirdActions) actions).getCallTimeLimit();
112 @RuleAction(label = "get the last error code", description = "Get the value of LASTERRORCODE.")
113 public @ActionOutput(name = "getLastErrorCode", type = "java.lang.String") String getLastErrorCode() {
114 logger.debug("Doorbird action 'getLastErrorCode' called");
115 if (handler != null) {
116 return handler.actionGetLastErrorCode();
118 logger.info("Doorbird Action service ThingHandler is null!");
123 public static String getLastErrorCode(ThingActions actions) {
124 return ((DoorbirdActions) actions).getLastErrorCode();
127 @RuleAction(label = "get the last error text", description = "Get the value of LASTERRORTEXT.")
128 public @ActionOutput(name = "getLastErrorText", type = "java.lang.String") String getLastErrorText() {
129 logger.debug("Doorbird action 'getLastErrorText' called");
130 if (handler != null) {
131 return handler.actionGetLastErrorText();
133 logger.info("Doorbird Action service ThingHandler is null!");
138 public static String getLastErrorText(ThingActions actions) {
139 return ((DoorbirdActions) actions).getLastErrorText();