2 * Copyright (c) 2010-2020 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) {
45 this.handler = (DoorbellHandler) handler;
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(@Nullable ThingActions actions) {
65 if (actions instanceof DoorbirdActions) {
66 ((DoorbirdActions) actions).restart();
68 throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
72 @RuleAction(label = "hangup a SIP call", description = "Hangup SIP call.")
73 public void sipHangup() {
74 logger.debug("Doorbird action 'sipHangup' called");
75 if (handler != null) {
76 handler.actionSIPHangup();
78 logger.info("Doorbird Action service ThingHandler is null!");
82 public static void sipHangup(@Nullable ThingActions actions) {
83 if (actions instanceof DoorbirdActions) {
84 ((DoorbirdActions) actions).sipHangup();
86 throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
90 @RuleAction(label = "get the ring time limit", description = "Get the value of RING_TIME_LIMIT.")
91 public @ActionOutput(name = "getRingTimeLimit", type = "java.lang.String") String getRingTimeLimit() {
92 logger.debug("Doorbird action 'getRingTimeLimit' called");
93 if (handler != null) {
94 return handler.actionGetRingTimeLimit();
96 logger.info("Doorbird Action service ThingHandler is null!");
101 public static String getRingTimeLimit(@Nullable ThingActions actions) {
102 if (actions instanceof DoorbirdActions) {
103 return ((DoorbirdActions) actions).getRingTimeLimit();
105 throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
109 @RuleAction(label = "get the call time limit", description = "Get the value of CALL_TIME_LIMIT.")
110 public @ActionOutput(name = "getCallTimeLimit", type = "java.lang.String") String getCallTimeLimit() {
111 logger.debug("Doorbird action 'getCallTimeLimit' called");
112 if (handler != null) {
113 return handler.actionGetCallTimeLimit();
115 logger.info("Doorbird Action service ThingHandler is null!");
120 public static String getCallTimeLimit(@Nullable ThingActions actions) {
121 if (actions instanceof DoorbirdActions) {
122 return ((DoorbirdActions) actions).getCallTimeLimit();
124 throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
128 @RuleAction(label = "get the last error code", description = "Get the value of LASTERRORCODE.")
129 public @ActionOutput(name = "getLastErrorCode", type = "java.lang.String") String getLastErrorCode() {
130 logger.debug("Doorbird action 'getLastErrorCode' called");
131 if (handler != null) {
132 return handler.actionGetLastErrorCode();
134 logger.info("Doorbird Action service ThingHandler is null!");
139 public static String getLastErrorCode(@Nullable ThingActions actions) {
140 if (actions instanceof DoorbirdActions) {
141 return ((DoorbirdActions) actions).getLastErrorCode();
143 throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
147 @RuleAction(label = "get the last error text", description = "Get the value of LASTERRORTEXT.")
148 public @ActionOutput(name = "getLastErrorText", type = "java.lang.String") String getLastErrorText() {
149 logger.debug("Doorbird action 'getLastErrorText' called");
150 if (handler != null) {
151 return handler.actionGetLastErrorText();
153 logger.info("Doorbird Action service ThingHandler is null!");
158 public static String getLastErrorText(@Nullable ThingActions actions) {
159 if (actions instanceof DoorbirdActions) {
160 return ((DoorbirdActions) actions).getLastErrorText();
162 throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");