]> git.basschouten.com Git - openhab-addons.git/blob
a47a7bf6f730ce7603cc4bb96451829347ffda5c
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.doorbird.internal.action;
14
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;
25
26 /**
27  * The {@link DoorbirdActions} defines rule actions for the doorbird binding.
28  *
29  * @author Mark Hilbush - Initial contribution
30  */
31 @ThingActionsScope(name = "doorbird")
32 @NonNullByDefault
33 public class DoorbirdActions implements ThingActions {
34     private final Logger logger = LoggerFactory.getLogger(DoorbirdActions.class);
35
36     private @Nullable DoorbellHandler handler;
37
38     public DoorbirdActions() {
39         logger.debug("DoorbirdActions service created");
40     }
41
42     @Override
43     public void setThingHandler(@Nullable ThingHandler handler) {
44         if (handler instanceof DoorbellHandler doorbellHandler) {
45             this.handler = doorbellHandler;
46         }
47     }
48
49     @Override
50     public @Nullable ThingHandler getThingHandler() {
51         return handler;
52     }
53
54     @RuleAction(label = "restart the Doorbird", description = "Restarts the Doorbird device.")
55     public void restart() {
56         logger.debug("Doorbird action 'restart' called");
57         DoorbellHandler handler = this.handler;
58         if (handler != null) {
59             handler.actionRestart();
60         } else {
61             logger.info("Doorbird Action service ThingHandler is null!");
62         }
63     }
64
65     public static void restart(ThingActions actions) {
66         ((DoorbirdActions) actions).restart();
67     }
68
69     @RuleAction(label = "hangup a SIP call", description = "Hangup SIP call.")
70     public void sipHangup() {
71         logger.debug("Doorbird action 'sipHangup' called");
72         DoorbellHandler handler = this.handler;
73         if (handler != null) {
74             handler.actionSIPHangup();
75         } else {
76             logger.info("Doorbird Action service ThingHandler is null!");
77         }
78     }
79
80     public static void sipHangup(ThingActions actions) {
81         ((DoorbirdActions) actions).sipHangup();
82     }
83
84     @RuleAction(label = "get the ring time limit", description = "Get the value of RING_TIME_LIMIT.")
85     public @ActionOutput(name = "getRingTimeLimit", type = "java.lang.String") String getRingTimeLimit() {
86         logger.debug("Doorbird action 'getRingTimeLimit' called");
87         DoorbellHandler handler = this.handler;
88         if (handler != null) {
89             return handler.actionGetRingTimeLimit();
90         } else {
91             logger.info("Doorbird Action service ThingHandler is null!");
92             return "";
93         }
94     }
95
96     public static String getRingTimeLimit(ThingActions actions) {
97         return ((DoorbirdActions) actions).getRingTimeLimit();
98     }
99
100     @RuleAction(label = "get the call time limit", description = "Get the value of CALL_TIME_LIMIT.")
101     public @ActionOutput(name = "getCallTimeLimit", type = "java.lang.String") String getCallTimeLimit() {
102         logger.debug("Doorbird action 'getCallTimeLimit' called");
103         DoorbellHandler handler = this.handler;
104         if (handler != null) {
105             return handler.actionGetCallTimeLimit();
106         } else {
107             logger.info("Doorbird Action service ThingHandler is null!");
108             return "";
109         }
110     }
111
112     public static String getCallTimeLimit(ThingActions actions) {
113         return ((DoorbirdActions) actions).getCallTimeLimit();
114     }
115
116     @RuleAction(label = "get the last error code", description = "Get the value of LASTERRORCODE.")
117     public @ActionOutput(name = "getLastErrorCode", type = "java.lang.String") String getLastErrorCode() {
118         logger.debug("Doorbird action 'getLastErrorCode' called");
119         DoorbellHandler handler = this.handler;
120         if (handler != null) {
121             return handler.actionGetLastErrorCode();
122         } else {
123             logger.info("Doorbird Action service ThingHandler is null!");
124             return "";
125         }
126     }
127
128     public static String getLastErrorCode(ThingActions actions) {
129         return ((DoorbirdActions) actions).getLastErrorCode();
130     }
131
132     @RuleAction(label = "get the last error text", description = "Get the value of LASTERRORTEXT.")
133     public @ActionOutput(name = "getLastErrorText", type = "java.lang.String") String getLastErrorText() {
134         logger.debug("Doorbird action 'getLastErrorText' called");
135         DoorbellHandler handler = this.handler;
136         if (handler != null) {
137             return handler.actionGetLastErrorText();
138         } else {
139             logger.info("Doorbird Action service ThingHandler is null!");
140             return "";
141         }
142     }
143
144     public static String getLastErrorText(ThingActions actions) {
145         return ((DoorbirdActions) actions).getLastErrorText();
146     }
147 }