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.radiothermostat.internal;
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;
27 * Some automation actions to be used with a {@link RadioThermostatThingActions}
29 * @author Michael Lobstein - initial contribution
31 @ThingActionsScope(name = "radiothermostat")
33 public class RadioThermostatThingActions implements ThingActions {
34 private final Logger logger = LoggerFactory.getLogger(RadioThermostatThingActions.class);
36 private @Nullable RadioThermostatHandler handler;
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");
45 RadioThermostatHandler localHandler = handler;
46 if (localHandler != null) {
47 localHandler.handleRawCommand(rawCommand);
48 logger.debug("sendRawCommand called with raw command: {}", rawCommand);
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");
60 RadioThermostatHandler localHandler = handler;
61 if (localHandler != null) {
62 localHandler.handleRawCommand(rawCommand, resource);
63 logger.debug("sendRawCommand called with raw command: {}, resource: {}", rawCommand, resource);
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);
72 public static void sendRawCommand(ThingActions actions, @Nullable String rawCommand, @Nullable String resource) {
73 ((RadioThermostatThingActions) actions).sendRawCommand(rawCommand, resource);
77 public void setThingHandler(@Nullable ThingHandler handler) {
78 this.handler = (RadioThermostatHandler) handler;
82 public @Nullable ThingHandler getThingHandler() {