]> git.basschouten.com Git - openhab-addons.git/blob
ef5530b48fc4e989d8b73dbfa85f766fa99f52fb
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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(@Nullable ThingActions actions, @Nullable Long duration) {
59         if (actions instanceof AVMFritzHeatingActions) {
60             ((AVMFritzHeatingActions) actions).setBoostMode(duration);
61         } else {
62             throw new IllegalArgumentException("Actions is not an instance of AVMFritzHeatingActions");
63         }
64     }
65
66     @RuleAction(label = "@text/setWindowOpenModeActionLabel", description = "@text/setWindowOpenModeActionDescription")
67     public void setWindowOpenMode(
68             @ActionInput(name = "Duration", label = "@text/setWindowOpenModeDurationInputLabel", description = "@text/setWindowOpenModeDurationInputDescription", type = "java.lang.Long", required = true) @Nullable Long duration) {
69         AVMFritzHeatingActionsHandler actionsHandler = handler;
70         if (actionsHandler == null) {
71             throw new IllegalArgumentException("AVMFritzHeatingActions ThingHandler is null!");
72         }
73         if (duration == null) {
74             throw new IllegalArgumentException("Cannot set Window Open mode as 'duration' is null!");
75         }
76         actionsHandler.setWindowOpenMode(duration.longValue());
77     }
78
79     public static void setWindowOpenMode(@Nullable ThingActions actions, @Nullable Long duration) {
80         if (actions instanceof AVMFritzHeatingActions) {
81             ((AVMFritzHeatingActions) actions).setWindowOpenMode(duration);
82         } else {
83             throw new IllegalArgumentException("Actions is not an instance of AVMFritzHeatingActions");
84         }
85     }
86 }