]> git.basschouten.com Git - openhab-addons.git/blob
0e1831c42f900e9c89cef3aeab8967cc56497a52
[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.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) {
45             this.handler = (DoorbellHandler) handler;
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         if (handler != null) {
58             handler.actionRestart();
59         } else {
60             logger.info("Doorbird Action service ThingHandler is null!");
61         }
62     }
63
64     public static void restart(ThingActions actions) {
65         ((DoorbirdActions) actions).restart();
66     }
67
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();
73         } else {
74             logger.info("Doorbird Action service ThingHandler is null!");
75         }
76     }
77
78     public static void sipHangup(ThingActions actions) {
79         ((DoorbirdActions) actions).sipHangup();
80     }
81
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();
87         } else {
88             logger.info("Doorbird Action service ThingHandler is null!");
89             return "";
90         }
91     }
92
93     public static String getRingTimeLimit(ThingActions actions) {
94         return ((DoorbirdActions) actions).getRingTimeLimit();
95     }
96
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();
102         } else {
103             logger.info("Doorbird Action service ThingHandler is null!");
104             return "";
105         }
106     }
107
108     public static String getCallTimeLimit(ThingActions actions) {
109         return ((DoorbirdActions) actions).getCallTimeLimit();
110     }
111
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();
117         } else {
118             logger.info("Doorbird Action service ThingHandler is null!");
119             return "";
120         }
121     }
122
123     public static String getLastErrorCode(ThingActions actions) {
124         return ((DoorbirdActions) actions).getLastErrorCode();
125     }
126
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();
132         } else {
133             logger.info("Doorbird Action service ThingHandler is null!");
134             return "";
135         }
136     }
137
138     public static String getLastErrorText(ThingActions actions) {
139         return ((DoorbirdActions) actions).getLastErrorText();
140     }
141 }