2 * Copyright (c) 2010-2024 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.warmup.internal.action;
15 import javax.measure.quantity.Temperature;
16 import javax.measure.quantity.Time;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.binding.warmup.internal.handler.RoomHandler;
21 import org.openhab.core.automation.annotation.ActionInput;
22 import org.openhab.core.automation.annotation.RuleAction;
23 import org.openhab.core.library.types.QuantityType;
24 import org.openhab.core.thing.binding.ThingActions;
25 import org.openhab.core.thing.binding.ThingActionsScope;
26 import org.openhab.core.thing.binding.ThingHandler;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 * @author James Melville - Initial contribution
33 @ThingActionsScope(name = "warmup")
35 public class WarmupActions implements ThingActions {
37 private final Logger logger = LoggerFactory.getLogger(WarmupActions.class);
39 private @Nullable RoomHandler handler;
41 public WarmupActions() {
42 logger.debug("Warmup action service instantiated");
46 public void setThingHandler(@Nullable ThingHandler handler) {
47 if (handler instanceof RoomHandler roomHandler) {
48 this.handler = roomHandler;
53 public @Nullable ThingHandler getThingHandler() {
57 @RuleAction(label = "override", description = "Overrides the thermostat state for a specified time")
58 public void setOverride(
59 @ActionInput(name = "temperature", label = "Temperature") @Nullable QuantityType<Temperature> temperature,
60 @ActionInput(name = "duration", label = "Duration") @Nullable QuantityType<Time> duration) {
61 logger.debug("setOverride action called");
62 RoomHandler handler = this.handler;
63 if (handler != null && temperature != null && duration != null) {
64 handler.setOverride(temperature, duration);
66 logger.warn("Warmup Action service argument is null!");
70 public static void setOverride(@Nullable ThingActions actions, @Nullable QuantityType<Temperature> temperature,
71 @Nullable QuantityType<Time> duration) {
72 if (actions instanceof WarmupActions warmupActions) {
73 warmupActions.setOverride(temperature, duration);
75 throw new IllegalArgumentException("Instance is not a WarmupActions class.");