]> git.basschouten.com Git - openhab-addons.git/blob
a9c485763f5830107167b89df08647cda5488212
[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.radiothermostat.internal;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.radiothermostat.internal.handler.RadioThermostatHandler;
18 import org.openhab.core.automation.annotation.ActionInput;
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  * Some automation actions to be used with a {@link RadioThermostatThingActions}
28  *
29  * @author Michael Lobstein - initial contribution
30  */
31 @ThingActionsScope(name = "radiothermostat")
32 @NonNullByDefault
33 public class RadioThermostatThingActions implements ThingActions {
34     private final Logger logger = LoggerFactory.getLogger(RadioThermostatThingActions.class);
35
36     private @Nullable RadioThermostatHandler handler;
37
38     @RuleAction(label = "send a raw command", description = "Send a raw command to the thermostat's 'tstat' endpoint.")
39     public void sendRawCommand(@ActionInput(name = "sendRawCommand") @Nullable String rawCommand) {
40         if (rawCommand == null) {
41             logger.warn("sendRawCommand called with null command, ignoring");
42             return;
43         }
44
45         RadioThermostatHandler localHandler = handler;
46         if (localHandler != null) {
47             localHandler.handleRawCommand(rawCommand);
48             logger.debug("sendRawCommand called with raw command: {}", rawCommand);
49         }
50     }
51
52     @RuleAction(label = "send a raw command", description = "Send a raw command to a specific endpoint on the thermostat.")
53     public void sendRawCommand(@ActionInput(name = "sendRawCommand") @Nullable String rawCommand,
54             @Nullable String resource) {
55         if (rawCommand == null || resource == null) {
56             logger.warn("sendRawCommand called with null command, ignoring");
57             return;
58         }
59
60         RadioThermostatHandler localHandler = handler;
61         if (localHandler != null) {
62             localHandler.handleRawCommand(rawCommand, resource);
63             logger.debug("sendRawCommand called with raw command: {}, resource: {}", rawCommand, resource);
64         }
65     }
66
67     /** Static aliases to support the old DSL rules engine and make the action available there. */
68     public static void sendRawCommand(ThingActions actions, @Nullable String rawCommand) {
69         ((RadioThermostatThingActions) actions).sendRawCommand(rawCommand);
70     }
71
72     public static void sendRawCommand(ThingActions actions, @Nullable String rawCommand, @Nullable String resource) {
73         ((RadioThermostatThingActions) actions).sendRawCommand(rawCommand, resource);
74     }
75
76     @Override
77     public void setThingHandler(@Nullable ThingHandler handler) {
78         this.handler = (RadioThermostatHandler) handler;
79     }
80
81     @Override
82     public @Nullable ThingHandler getThingHandler() {
83         return handler;
84     }
85 }