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 (handler != null) {
51 handler.writeValue(variableName, "1");
53 } catch (HeliosException e) {
54 logger.warn("Error executing action triggering switch for variable {}: {}", variableName, 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 triggerSwitch(HeliosEasyControlsBindingConstants.FILTER_CHANGE_RESET);
63 public static void resetFilterChangeTimer(ThingActions actions) {
64 ((HeliosEasyControlsActions) actions).resetFilterChangeTimer();
67 @RuleAction(label = "reset error messages", description = "Reset error/warning/info messages.")
68 public void resetErrors() {
69 triggerSwitch(HeliosEasyControlsBindingConstants.RESET_FLAG);
72 public static void resetErrors(ThingActions actions) {
73 ((HeliosEasyControlsActions) actions).resetErrors();
76 @RuleAction(label = "reset to factory defaults", description = "Reset device to factory defaults.")
77 public void resetToFactoryDefaults() {
78 triggerSwitch(HeliosEasyControlsBindingConstants.FACTORY_RESET);
81 public static void resetToFactoryDefaults(ThingActions actions) {
82 ((HeliosEasyControlsActions) actions).resetToFactoryDefaults();
85 @RuleAction(label = "reset individual switching times", description = "Reset individual switching times.")
86 public void resetSwitchingTimes() {
87 triggerSwitch(HeliosEasyControlsBindingConstants.FACTORY_SETTING_WZU);
90 public static void resetSwitchingTimes(ThingActions actions) {
91 ((HeliosEasyControlsActions) actions).resetSwitchingTimes();
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();
102 public static void setSysDateTime(ThingActions actions) {
103 ((HeliosEasyControlsActions) actions).setSysDateTime();
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);
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);
120 public static void setBypassFrom(ThingActions actions, int day, int month) {
121 ((HeliosEasyControlsActions) actions).setBypassFrom(day, month);
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);
131 public static void setBypassTo(ThingActions actions, int day, int month) {
132 ((HeliosEasyControlsActions) actions).setBypassTo(day, month);