]> git.basschouten.com Git - openhab-addons.git/blob
964127926e6de41cd168750f460f7168e6f13f08
[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 javax.measure.quantity.Temperature;
16 import javax.measure.quantity.Time;
17
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;
29
30 /**
31  * @author James Melville - Initial contribution
32  */
33 @ThingActionsScope(name = "warmup")
34 @NonNullByDefault
35 public class WarmupActions implements ThingActions {
36
37     private final Logger logger = LoggerFactory.getLogger(WarmupActions.class);
38
39     private @Nullable RoomHandler handler;
40
41     public WarmupActions() {
42         logger.debug("Warmup action service instantiated");
43     }
44
45     @Override
46     public void setThingHandler(@Nullable ThingHandler handler) {
47         if (handler instanceof RoomHandler roomHandler) {
48             this.handler = roomHandler;
49         }
50     }
51
52     @Override
53     public @Nullable ThingHandler getThingHandler() {
54         return handler;
55     }
56
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);
65         } else {
66             logger.warn("Warmup Action service argument is null!");
67         }
68     }
69
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);
74         } else {
75             throw new IllegalArgumentException("Instance is not a WarmupActions class.");
76         }
77     }
78 }