Rework ThingActions (#8755)
* Remove duplication by making use of default Java generated exceptions * Make ThingActions labels/descriptions more consistent Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
@@ -47,67 +47,51 @@ public class HeliosEasyControlsActions implements ThingActions {
|
||||
|
||||
private void triggerSwitch(String variableName) {
|
||||
try {
|
||||
if (this.handler != null) {
|
||||
this.handler.writeValue(variableName, "1");
|
||||
if (handler != null) {
|
||||
handler.writeValue(variableName, "1");
|
||||
}
|
||||
} catch (HeliosException e) {
|
||||
logger.warn("Error executing action 'resetFilterChangeTimer': {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@RuleAction(label = "Reset filter change timer", description = "Sets the filter change timer back to the configured interval")
|
||||
@RuleAction(label = "reset filter change timer", description = "Sets the filter change timer back to the configured interval.")
|
||||
public void resetFilterChangeTimer() {
|
||||
this.triggerSwitch(HeliosEasyControlsBindingConstants.FILTER_CHANGE_RESET);
|
||||
triggerSwitch(HeliosEasyControlsBindingConstants.FILTER_CHANGE_RESET);
|
||||
}
|
||||
|
||||
public static void resetFilterChangeTimer(@Nullable ThingActions actions) {
|
||||
if (actions instanceof HeliosEasyControlsActions) {
|
||||
((HeliosEasyControlsActions) actions).resetFilterChangeTimer();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class.");
|
||||
}
|
||||
public static void resetFilterChangeTimer(ThingActions actions) {
|
||||
((HeliosEasyControlsActions) actions).resetFilterChangeTimer();
|
||||
}
|
||||
|
||||
@RuleAction(label = "Reset error messages", description = "Reset error/warning/info messages")
|
||||
@RuleAction(label = "reset error messages", description = "Reset error/warning/info messages.")
|
||||
public void resetErrors() {
|
||||
this.triggerSwitch(HeliosEasyControlsBindingConstants.RESET_FLAG);
|
||||
triggerSwitch(HeliosEasyControlsBindingConstants.RESET_FLAG);
|
||||
}
|
||||
|
||||
public static void resetErrors(@Nullable ThingActions actions) {
|
||||
if (actions instanceof HeliosEasyControlsActions) {
|
||||
((HeliosEasyControlsActions) actions).resetErrors();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class.");
|
||||
}
|
||||
public static void resetErrors(ThingActions actions) {
|
||||
((HeliosEasyControlsActions) actions).resetErrors();
|
||||
}
|
||||
|
||||
@RuleAction(label = "Reset to factory defaults", description = "Reset device to factory defaults")
|
||||
@RuleAction(label = "reset to factory defaults", description = "Reset device to factory defaults.")
|
||||
public void resetToFactoryDefaults() {
|
||||
this.triggerSwitch(HeliosEasyControlsBindingConstants.FACTORY_RESET);
|
||||
triggerSwitch(HeliosEasyControlsBindingConstants.FACTORY_RESET);
|
||||
}
|
||||
|
||||
public static void resetToFactoryDefaults(@Nullable ThingActions actions) {
|
||||
if (actions instanceof HeliosEasyControlsActions) {
|
||||
((HeliosEasyControlsActions) actions).resetToFactoryDefaults();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class.");
|
||||
}
|
||||
public static void resetToFactoryDefaults(ThingActions actions) {
|
||||
((HeliosEasyControlsActions) actions).resetToFactoryDefaults();
|
||||
}
|
||||
|
||||
@RuleAction(label = "Reset individual switching times", description = "Reset individual switching times")
|
||||
@RuleAction(label = "reset individual switching times", description = "Reset individual switching times.")
|
||||
public void resetSwitchingTimes() {
|
||||
this.triggerSwitch(HeliosEasyControlsBindingConstants.FACTORY_SETTING_WZU);
|
||||
triggerSwitch(HeliosEasyControlsBindingConstants.FACTORY_SETTING_WZU);
|
||||
}
|
||||
|
||||
public static void resetSwitchingTimes(@Nullable ThingActions actions) {
|
||||
if (actions instanceof HeliosEasyControlsActions) {
|
||||
((HeliosEasyControlsActions) actions).resetSwitchingTimes();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class.");
|
||||
}
|
||||
public static void resetSwitchingTimes(ThingActions actions) {
|
||||
((HeliosEasyControlsActions) actions).resetSwitchingTimes();
|
||||
}
|
||||
|
||||
@RuleAction(label = "Set system date and time", description = "Sets the device's system date and time based on OH's system date and time")
|
||||
@RuleAction(label = "set system date and time", description = "Sets the device's system date and time based on OH's system date and time.")
|
||||
public void setSysDateTime() {
|
||||
HeliosEasyControlsHandler handler = this.handler;
|
||||
if (handler != null) {
|
||||
@@ -115,12 +99,8 @@ public class HeliosEasyControlsActions implements ThingActions {
|
||||
}
|
||||
}
|
||||
|
||||
public static void setSysDateTime(@Nullable ThingActions actions) {
|
||||
if (actions instanceof HeliosEasyControlsActions) {
|
||||
((HeliosEasyControlsActions) actions).setSysDateTime();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class.");
|
||||
}
|
||||
public static void setSysDateTime(ThingActions actions) {
|
||||
((HeliosEasyControlsActions) actions).setSysDateTime();
|
||||
}
|
||||
|
||||
private void setBypass(boolean from, int day, int month) {
|
||||
@@ -130,33 +110,25 @@ public class HeliosEasyControlsActions implements ThingActions {
|
||||
}
|
||||
}
|
||||
|
||||
@RuleAction(label = "Set the bypass from day and month", description = "Sets the day and month from when the bypass should be active")
|
||||
@RuleAction(label = "set the bypass from day and month", description = "Sets the day and month from when the bypass should be active.")
|
||||
public void setBypassFrom(
|
||||
@ActionInput(name = "day", label = "bypass from day", description = "The day from when the bypass should be active") int day,
|
||||
@ActionInput(name = "month", label = "bypass from month", description = "The month from when the bypass should be active") int month) {
|
||||
this.setBypass(true, day, month);
|
||||
setBypass(true, day, month);
|
||||
}
|
||||
|
||||
public static void setBypassFrom(@Nullable ThingActions actions, int day, int month) {
|
||||
if (actions instanceof HeliosEasyControlsActions) {
|
||||
((HeliosEasyControlsActions) actions).setBypassFrom(day, month);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class.");
|
||||
}
|
||||
public static void setBypassFrom(ThingActions actions, int day, int month) {
|
||||
((HeliosEasyControlsActions) actions).setBypassFrom(day, month);
|
||||
}
|
||||
|
||||
@RuleAction(label = "Set the bypass to day and month", description = "Sets the day and month until when the bypass should be active")
|
||||
@RuleAction(label = "set the bypass to day and month", description = "Sets the day and month until when the bypass should be active.")
|
||||
public void setBypassTo(
|
||||
@ActionInput(name = "day", label = "bypass to day", description = "The day until when the bypass should be active") int day,
|
||||
@ActionInput(name = "month", label = "bypass to month", description = "The month until when the bypass should be active") int month) {
|
||||
this.setBypass(false, day, month);
|
||||
setBypass(false, day, month);
|
||||
}
|
||||
|
||||
public static void setBypassTo(@Nullable ThingActions actions, int day, int month) {
|
||||
if (actions instanceof HeliosEasyControlsActions) {
|
||||
((HeliosEasyControlsActions) actions).setBypassTo(day, month);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class.");
|
||||
}
|
||||
public static void setBypassTo(ThingActions actions, int day, int month) {
|
||||
((HeliosEasyControlsActions) actions).setBypassTo(day, month);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user