]> git.basschouten.com Git - openhab-addons.git/blob
ba0cab62f9bb80f049483a3af4c3cb8e3f47ba2c
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.avmfritz.internal.actions;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.avmfritz.internal.handler.AVMFritzHeatingActionsHandler;
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
24 /**
25  * The {@link AVMFritzHeatingActions} defines thing actions for heating devices / groups of the avmfritz binding.
26  *
27  * @author Christoph Weitkamp - Initial contribution
28  */
29 @ThingActionsScope(name = "avmfritz")
30 @NonNullByDefault
31 public class AVMFritzHeatingActions implements ThingActions {
32
33     private @Nullable AVMFritzHeatingActionsHandler handler;
34
35     @Override
36     public void setThingHandler(@Nullable ThingHandler handler) {
37         this.handler = (AVMFritzHeatingActionsHandler) handler;
38     }
39
40     @Override
41     public @Nullable ThingHandler getThingHandler() {
42         return handler;
43     }
44
45     @RuleAction(label = "@text/setBoostModeModeActionLabel", description = "@text/setBoostModeActionDescription")
46     public void setBoostMode(
47             @ActionInput(name = "Duration", label = "@text/setBoostModeDurationInputLabel", description = "@text/setBoostModeDurationInputDescription", type = "java.lang.Long", required = true) @Nullable Long duration) {
48         AVMFritzHeatingActionsHandler actionsHandler = handler;
49         if (actionsHandler == null) {
50             throw new IllegalArgumentException("AVMFritzHeatingActions ThingHandler is null!");
51         }
52         if (duration == null) {
53             throw new IllegalArgumentException("Cannot set Boost mode as 'duration' is null!");
54         }
55         actionsHandler.setBoostMode(duration.longValue());
56     }
57
58     public static void setBoostMode(ThingActions actions, @Nullable Long duration) {
59         ((AVMFritzHeatingActions) actions).setBoostMode(duration);
60     }
61
62     @RuleAction(label = "@text/setWindowOpenModeActionLabel", description = "@text/setWindowOpenModeActionDescription")
63     public void setWindowOpenMode(
64             @ActionInput(name = "Duration", label = "@text/setWindowOpenModeDurationInputLabel", description = "@text/setWindowOpenModeDurationInputDescription", type = "java.lang.Long", required = true) @Nullable Long duration) {
65         AVMFritzHeatingActionsHandler actionsHandler = handler;
66         if (actionsHandler == null) {
67             throw new IllegalArgumentException("AVMFritzHeatingActions ThingHandler is null!");
68         }
69         if (duration == null) {
70             throw new IllegalArgumentException("Cannot set Window Open mode as 'duration' is null!");
71         }
72         actionsHandler.setWindowOpenMode(duration.longValue());
73     }
74
75     public static void setWindowOpenMode(ThingActions actions, @Nullable Long duration) {
76         ((AVMFritzHeatingActions) actions).setWindowOpenMode(duration);
77     }
78 }