]> git.basschouten.com Git - openhab-addons.git/blob
389a7bd58d2436023c9440623e5cd505a2246bff
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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(@Nullable ThingActions actions) {
65         if (actions instanceof DoorbirdActions) {
66             ((DoorbirdActions) actions).restart();
67         } else {
68             throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
69         }
70     }
71
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();
77         } else {
78             logger.info("Doorbird Action service ThingHandler is null!");
79         }
80     }
81
82     public static void sipHangup(@Nullable ThingActions actions) {
83         if (actions instanceof DoorbirdActions) {
84             ((DoorbirdActions) actions).sipHangup();
85         } else {
86             throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
87         }
88     }
89
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();
95         } else {
96             logger.info("Doorbird Action service ThingHandler is null!");
97             return "";
98         }
99     }
100
101     public static String getRingTimeLimit(@Nullable ThingActions actions) {
102         if (actions instanceof DoorbirdActions) {
103             return ((DoorbirdActions) actions).getRingTimeLimit();
104         } else {
105             throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
106         }
107     }
108
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();
114         } else {
115             logger.info("Doorbird Action service ThingHandler is null!");
116             return "";
117         }
118     }
119
120     public static String getCallTimeLimit(@Nullable ThingActions actions) {
121         if (actions instanceof DoorbirdActions) {
122             return ((DoorbirdActions) actions).getCallTimeLimit();
123         } else {
124             throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
125         }
126     }
127
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();
133         } else {
134             logger.info("Doorbird Action service ThingHandler is null!");
135             return "";
136         }
137     }
138
139     public static String getLastErrorCode(@Nullable ThingActions actions) {
140         if (actions instanceof DoorbirdActions) {
141             return ((DoorbirdActions) actions).getLastErrorCode();
142         } else {
143             throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
144         }
145     }
146
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();
152         } else {
153             logger.info("Doorbird Action service ThingHandler is null!");
154             return "";
155         }
156     }
157
158     public static String getLastErrorText(@Nullable ThingActions actions) {
159         if (actions instanceof DoorbirdActions) {
160             return ((DoorbirdActions) actions).getLastErrorText();
161         } else {
162             throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
163         }
164     }
165 }