]> git.basschouten.com Git - openhab-addons.git/blob
3960205068ca6f941cec1fd4c7b333c52eb48a16
[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.warmup.internal.action;
14
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;
26
27 /**
28  * @author James Melville - Initial contribution
29  */
30 @ThingActionsScope(name = "warmup")
31 @NonNullByDefault
32 public class WarmupActions implements ThingActions {
33
34     private final Logger logger = LoggerFactory.getLogger(WarmupActions.class);
35
36     private @Nullable RoomHandler handler;
37
38     public WarmupActions() {
39         logger.debug("Warmup action service instantiated");
40     }
41
42     @Override
43     public void setThingHandler(@Nullable ThingHandler handler) {
44         if (handler instanceof RoomHandler roomHandler) {
45             this.handler = roomHandler;
46         }
47     }
48
49     @Override
50     public @Nullable ThingHandler getThingHandler() {
51         return handler;
52     }
53
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);
62         } else {
63             logger.warn("Warmup Action service argument is null!");
64         }
65     }
66
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);
71         } else {
72             throw new IllegalArgumentException("Instance is not a WarmupActions class.");
73         }
74     }
75 }