]> git.basschouten.com Git - openhab-addons.git/blob
5c867c2b919bff25430fd08f525eee7c6143c0c0
[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.volvooncall.internal.action;
14
15 import static org.openhab.binding.volvooncall.internal.VolvoOnCallBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.volvooncall.internal.handler.VehicleHandler;
20 import org.openhab.core.automation.annotation.ActionInput;
21 import org.openhab.core.automation.annotation.RuleAction;
22 import org.openhab.core.library.types.OnOffType;
23 import org.openhab.core.thing.binding.ThingActions;
24 import org.openhab.core.thing.binding.ThingActionsScope;
25 import org.openhab.core.thing.binding.ThingHandler;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 /**
30  * The {@link VolvoOnCallActions} class is responsible to call corresponding
31  * action on Vehicle Handler
32  *
33  * @author GaĆ«l L'hopital - Initial contribution
34  */
35 @ThingActionsScope(name = "volvooncall")
36 @NonNullByDefault
37 public class VolvoOnCallActions implements ThingActions {
38
39     private final Logger logger = LoggerFactory.getLogger(VolvoOnCallActions.class);
40
41     private @Nullable VehicleHandler handler;
42
43     public VolvoOnCallActions() {
44         logger.debug("Volvo On Call actions service instantiated");
45     }
46
47     @Override
48     public void setThingHandler(@Nullable ThingHandler handler) {
49         if (handler instanceof VehicleHandler vehicleHandler) {
50             this.handler = vehicleHandler;
51         }
52     }
53
54     @Override
55     public @Nullable ThingHandler getThingHandler() {
56         return handler;
57     }
58
59     @RuleAction(label = "close the car", description = "Closes the car")
60     public void closeCarCommand() {
61         logger.debug("closeCarCommand called");
62         VehicleHandler handler = this.handler;
63         if (handler != null) {
64             handler.actionOpenClose(LOCK, OnOffType.ON);
65         } else {
66             logger.warn("VolvoOnCall Action service ThingHandler is null!");
67         }
68     }
69
70     @RuleAction(label = "open the car", description = "Opens the car")
71     public void openCarCommand() {
72         logger.debug("openCarCommand called");
73         VehicleHandler handler = this.handler;
74         if (handler != null) {
75             handler.actionOpenClose(UNLOCK, OnOffType.OFF);
76         } else {
77             logger.warn("VolvoOnCall Action service ThingHandler is null!");
78         }
79     }
80
81     @RuleAction(label = "start the engine", description = "Starts the engine")
82     public void engineStartCommand(@ActionInput(name = "runtime", label = "Runtime") @Nullable Integer runtime) {
83         logger.debug("engineStartCommand called");
84         VehicleHandler handler = this.handler;
85         if (handler != null) {
86             handler.actionStart(runtime != null ? runtime : 5);
87         } else {
88             logger.warn("VolvoOnCall Action service ThingHandler is null!");
89         }
90     }
91
92     @RuleAction(label = "start the heater", description = "Starts car heater")
93     public void heaterStartCommand() {
94         logger.debug("heaterStartCommand called");
95         VehicleHandler handler = this.handler;
96         if (handler != null) {
97             handler.actionHeater(REMOTE_HEATER, true);
98         } else {
99             logger.warn("VolvoOnCall Action service ThingHandler is null!");
100         }
101     }
102
103     @RuleAction(label = "start preclimatization", description = "Starts the car heater")
104     public void preclimatizationStartCommand() {
105         logger.debug("preclimatizationStartCommand called");
106         VehicleHandler handler = this.handler;
107         if (handler != null) {
108             handler.actionHeater(PRECLIMATIZATION, true);
109         } else {
110             logger.warn("VolvoOnCall Action service ThingHandler is null!");
111         }
112     }
113
114     @RuleAction(label = "stop the heater", description = "Stops car heater")
115     public void heaterStopCommand() {
116         logger.debug("heaterStopCommand called");
117         VehicleHandler handler = this.handler;
118         if (handler != null) {
119             handler.actionHeater(REMOTE_HEATER, false);
120         } else {
121             logger.warn("VolvoOnCall Action service ThingHandler is null!");
122         }
123     }
124
125     @RuleAction(label = "stop preclimatization", description = "Stops the car heater")
126     public void preclimatizationStopCommand() {
127         logger.debug("preclimatizationStopCommand called");
128         VehicleHandler handler = this.handler;
129         if (handler != null) {
130             handler.actionHeater(PRECLIMATIZATION, false);
131         } else {
132             logger.warn("VolvoOnCall Action service ThingHandler is null!");
133         }
134     }
135
136     @RuleAction(label = "honk-blink", description = "Activates the horn and or lights of the car")
137     public void honkBlinkCommand(@ActionInput(name = "honk", label = "Honk") Boolean honk,
138             @ActionInput(name = "blink", label = "Blink") Boolean blink) {
139         logger.debug("honkBlinkCommand called");
140         VehicleHandler handler = this.handler;
141         if (handler != null) {
142             handler.actionHonkBlink(honk, blink);
143         } else {
144             logger.warn("VolvoOnCall Action service ThingHandler is null!");
145         }
146     }
147 }