2 * Copyright (c) 2010-2023 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.volvooncall.internal.action;
15 import static org.openhab.binding.volvooncall.internal.VolvoOnCallBindingConstants.*;
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;
30 * The {@link VolvoOnCallActions} class is responsible to call corresponding
31 * action on Vehicle Handler
33 * @author Gaƫl L'hopital - Initial contribution
35 @ThingActionsScope(name = "volvooncall")
37 public class VolvoOnCallActions implements ThingActions {
39 private final Logger logger = LoggerFactory.getLogger(VolvoOnCallActions.class);
41 private @Nullable VehicleHandler handler;
43 public VolvoOnCallActions() {
44 logger.debug("Volvo On Call actions service instantiated");
48 public void setThingHandler(@Nullable ThingHandler handler) {
49 if (handler instanceof VehicleHandler vehicleHandler) {
50 this.handler = vehicleHandler;
55 public @Nullable ThingHandler getThingHandler() {
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);
66 logger.warn("VolvoOnCall Action service ThingHandler is null!");
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);
77 logger.warn("VolvoOnCall Action service ThingHandler is null!");
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);
88 logger.warn("VolvoOnCall Action service ThingHandler is null!");
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);
99 logger.warn("VolvoOnCall Action service ThingHandler is null!");
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);
110 logger.warn("VolvoOnCall Action service ThingHandler is null!");
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);
121 logger.warn("VolvoOnCall Action service ThingHandler is null!");
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);
132 logger.warn("VolvoOnCall Action service ThingHandler is null!");
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);
144 logger.warn("VolvoOnCall Action service ThingHandler is null!");