]> git.basschouten.com Git - openhab-addons.git/blob
8efc8bb174c447a2b1f628a781ee6e8c7c22b419
[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.modbus.helioseasycontrols.internal;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.core.automation.annotation.ActionInput;
18 import org.openhab.core.automation.annotation.RuleAction;
19 import org.openhab.core.thing.binding.ThingActions;
20 import org.openhab.core.thing.binding.ThingActionsScope;
21 import org.openhab.core.thing.binding.ThingHandler;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 /**
26  * This class provides the actions available for the Helios device
27  *
28  * @author Bernhard Bauer - Initial contribution
29  */
30 @ThingActionsScope(name = "modbus.helioseasycontrols")
31 @NonNullByDefault
32 public class HeliosEasyControlsActions implements ThingActions {
33
34     private @Nullable HeliosEasyControlsHandler handler;
35
36     private final Logger logger = LoggerFactory.getLogger(HeliosEasyControlsActions.class);
37
38     @Override
39     public void setThingHandler(@Nullable ThingHandler handler) {
40         this.handler = (HeliosEasyControlsHandler) handler;
41     }
42
43     @Override
44     public @Nullable ThingHandler getThingHandler() {
45         return handler;
46     }
47
48     private void triggerSwitch(String variableName) {
49         try {
50             if (handler != null) {
51                 handler.writeValue(variableName, "1");
52             }
53         } catch (HeliosException e) {
54             logger.warn("Error executing action 'resetFilterChangeTimer': {}", e.getMessage());
55         }
56     }
57
58     @RuleAction(label = "reset filter change timer", description = "Sets the filter change timer back to the configured interval.")
59     public void resetFilterChangeTimer() {
60         triggerSwitch(HeliosEasyControlsBindingConstants.FILTER_CHANGE_RESET);
61     }
62
63     public static void resetFilterChangeTimer(ThingActions actions) {
64         ((HeliosEasyControlsActions) actions).resetFilterChangeTimer();
65     }
66
67     @RuleAction(label = "reset error messages", description = "Reset error/warning/info messages.")
68     public void resetErrors() {
69         triggerSwitch(HeliosEasyControlsBindingConstants.RESET_FLAG);
70     }
71
72     public static void resetErrors(ThingActions actions) {
73         ((HeliosEasyControlsActions) actions).resetErrors();
74     }
75
76     @RuleAction(label = "reset to factory defaults", description = "Reset device to factory defaults.")
77     public void resetToFactoryDefaults() {
78         triggerSwitch(HeliosEasyControlsBindingConstants.FACTORY_RESET);
79     }
80
81     public static void resetToFactoryDefaults(ThingActions actions) {
82         ((HeliosEasyControlsActions) actions).resetToFactoryDefaults();
83     }
84
85     @RuleAction(label = "reset individual switching times", description = "Reset individual switching times.")
86     public void resetSwitchingTimes() {
87         triggerSwitch(HeliosEasyControlsBindingConstants.FACTORY_SETTING_WZU);
88     }
89
90     public static void resetSwitchingTimes(ThingActions actions) {
91         ((HeliosEasyControlsActions) actions).resetSwitchingTimes();
92     }
93
94     @RuleAction(label = "set system date and time", description = "Sets the device's system date and time based on OH's system date and time.")
95     public void setSysDateTime() {
96         HeliosEasyControlsHandler handler = this.handler;
97         if (handler != null) {
98             handler.setSysDateTime();
99         }
100     }
101
102     public static void setSysDateTime(ThingActions actions) {
103         ((HeliosEasyControlsActions) actions).setSysDateTime();
104     }
105
106     private void setBypass(boolean from, int day, int month) {
107         HeliosEasyControlsHandler handler = this.handler;
108         if (handler != null) {
109             handler.setBypass(from, day, month);
110         }
111     }
112
113     @RuleAction(label = "set the bypass from day and month", description = "Sets the day and month from when the bypass should be active.")
114     public void setBypassFrom(
115             @ActionInput(name = "day", label = "bypass from day", description = "The day from when the bypass should be active") int day,
116             @ActionInput(name = "month", label = "bypass from month", description = "The month from when the bypass should be active") int month) {
117         setBypass(true, day, month);
118     }
119
120     public static void setBypassFrom(ThingActions actions, int day, int month) {
121         ((HeliosEasyControlsActions) actions).setBypassFrom(day, month);
122     }
123
124     @RuleAction(label = "set the bypass to day and month", description = "Sets the day and month until when the bypass should be active.")
125     public void setBypassTo(
126             @ActionInput(name = "day", label = "bypass to day", description = "The day until when the bypass should be active") int day,
127             @ActionInput(name = "month", label = "bypass to month", description = "The month until when the bypass should be active") int month) {
128         setBypass(false, day, month);
129     }
130
131     public static void setBypassTo(ThingActions actions, int day, int month) {
132         ((HeliosEasyControlsActions) actions).setBypassTo(day, month);
133     }
134 }