2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.modbus.helioseasycontrols.internal;
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;
26 * This class provides the actions available for the Helios device
28 * @author Bernhard Bauer - Initial contribution
30 @ThingActionsScope(name = "modbus.helioseasycontrols")
32 public class HeliosEasyControlsActions implements ThingActions {
34 private @Nullable HeliosEasyControlsHandler handler;
36 private final Logger logger = LoggerFactory.getLogger(HeliosEasyControlsActions.class);
39 public void setThingHandler(@Nullable ThingHandler handler) {
40 this.handler = (HeliosEasyControlsHandler) handler;
44 public @Nullable ThingHandler getThingHandler() {
48 private void triggerSwitch(String variableName) {
50 if (this.handler != null) {
51 this.handler.writeValue(variableName, "1");
53 } catch (HeliosException e) {
54 logger.warn("Error executing action 'resetFilterChangeTimer': {}", e.getMessage());
58 @RuleAction(label = "Reset filter change timer", description = "Sets the filter change timer back to the configured interval")
59 public void resetFilterChangeTimer() {
60 this.triggerSwitch(HeliosEasyControlsBindingConstants.FILTER_CHANGE_RESET);
63 public static void resetFilterChangeTimer(@Nullable ThingActions actions) {
64 if (actions instanceof HeliosEasyControlsActions) {
65 ((HeliosEasyControlsActions) actions).resetFilterChangeTimer();
67 throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class.");
71 @RuleAction(label = "Reset error messages", description = "Reset error/warning/info messages")
72 public void resetErrors() {
73 this.triggerSwitch(HeliosEasyControlsBindingConstants.RESET_FLAG);
76 public static void resetErrors(@Nullable ThingActions actions) {
77 if (actions instanceof HeliosEasyControlsActions) {
78 ((HeliosEasyControlsActions) actions).resetErrors();
80 throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class.");
84 @RuleAction(label = "Reset to factory defaults", description = "Reset device to factory defaults")
85 public void resetToFactoryDefaults() {
86 this.triggerSwitch(HeliosEasyControlsBindingConstants.FACTORY_RESET);
89 public static void resetToFactoryDefaults(@Nullable ThingActions actions) {
90 if (actions instanceof HeliosEasyControlsActions) {
91 ((HeliosEasyControlsActions) actions).resetToFactoryDefaults();
93 throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class.");
97 @RuleAction(label = "Reset individual switching times", description = "Reset individual switching times")
98 public void resetSwitchingTimes() {
99 this.triggerSwitch(HeliosEasyControlsBindingConstants.FACTORY_SETTING_WZU);
102 public static void resetSwitchingTimes(@Nullable ThingActions actions) {
103 if (actions instanceof HeliosEasyControlsActions) {
104 ((HeliosEasyControlsActions) actions).resetSwitchingTimes();
106 throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class.");
110 @RuleAction(label = "Set system date and time", description = "Sets the device's system date and time based on OH's system date and time")
111 public void setSysDateTime() {
112 HeliosEasyControlsHandler handler = this.handler;
113 if (handler != null) {
114 handler.setSysDateTime();
118 public static void setSysDateTime(@Nullable ThingActions actions) {
119 if (actions instanceof HeliosEasyControlsActions) {
120 ((HeliosEasyControlsActions) actions).setSysDateTime();
122 throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class.");
126 private void setBypass(boolean from, int day, int month) {
127 HeliosEasyControlsHandler handler = this.handler;
128 if (handler != null) {
129 handler.setBypass(from, day, month);
133 @RuleAction(label = "Set the bypass from day and month", description = "Sets the day and month from when the bypass should be active")
134 public void setBypassFrom(
135 @ActionInput(name = "day", label = "bypass from day", description = "The day from when the bypass should be active") int day,
136 @ActionInput(name = "month", label = "bypass from month", description = "The month from when the bypass should be active") int month) {
137 this.setBypass(true, day, month);
140 public static void setBypassFrom(@Nullable ThingActions actions, int day, int month) {
141 if (actions instanceof HeliosEasyControlsActions) {
142 ((HeliosEasyControlsActions) actions).setBypassFrom(day, month);
144 throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class.");
148 @RuleAction(label = "Set the bypass to day and month", description = "Sets the day and month until when the bypass should be active")
149 public void setBypassTo(
150 @ActionInput(name = "day", label = "bypass to day", description = "The day until when the bypass should be active") int day,
151 @ActionInput(name = "month", label = "bypass to month", description = "The month until when the bypass should be active") int month) {
152 this.setBypass(false, day, month);
155 public static void setBypassTo(@Nullable ThingActions actions, int day, int month) {
156 if (actions instanceof HeliosEasyControlsActions) {
157 ((HeliosEasyControlsActions) actions).setBypassTo(day, month);
159 throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class.");