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 org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.warmup.internal.handler.RoomHandler;
18 import org.openhab.core.automation.annotation.ActionInput;
19 import org.openhab.core.automation.annotation.RuleAction;
20 import org.openhab.core.library.types.QuantityType;
21 import org.openhab.core.thing.binding.ThingActions;
22 import org.openhab.core.thing.binding.ThingActionsScope;
23 import org.openhab.core.thing.binding.ThingHandler;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
28 * @author James Melville - Initial contribution
30 @ThingActionsScope(name = "warmup")
32 public class WarmupActions implements ThingActions {
34 private final Logger logger = LoggerFactory.getLogger(WarmupActions.class);
36 private @Nullable RoomHandler handler;
38 public WarmupActions() {
39 logger.debug("Warmup action service instantiated");
43 public void setThingHandler(@Nullable ThingHandler handler) {
44 if (handler instanceof RoomHandler roomHandler) {
45 this.handler = roomHandler;
50 public @Nullable ThingHandler getThingHandler() {
54 @RuleAction(label = "override", description = "Overrides the thermostat state for a specified time")
55 public void setOverride(
56 @ActionInput(name = "temperature", label = "Temperature") @Nullable QuantityType<?> temperature,
57 @ActionInput(name = "duration", label = "Duration") @Nullable QuantityType<?> duration) {
58 logger.debug("setOverride action called");
59 RoomHandler handler = this.handler;
60 if (handler != null && temperature != null && duration != null) {
61 handler.setOverride(temperature, duration);
63 logger.warn("Warmup Action service argument is null!");
67 public static void setOverride(@Nullable ThingActions actions, @Nullable QuantityType<?> temperature,
68 @Nullable QuantityType<?> duration) {
69 if (actions instanceof WarmupActions warmupActions) {
70 warmupActions.setOverride(temperature, duration);
72 throw new IllegalArgumentException("Instance is not a WarmupActions class.");