From 85af35474fd1ca31768caedfa5de14a5f5f8f9eb Mon Sep 17 00:00:00 2001 From: Bernhard Bauer Date: Tue, 24 Nov 2020 04:05:02 +0100 Subject: [PATCH] [helioseasycontrols] Range checks for bypass dates + documentation fixes (#9117) Signed-off-by: Bernhard Bauer --- .../README.md | 10 ++--- .../internal/HeliosEasyControlsActions.java | 2 +- .../internal/HeliosEasyControlsHandler.java | 41 ++++++++++++++++--- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/bundles/org.openhab.binding.modbus.helioseasycontrols/README.md b/bundles/org.openhab.binding.modbus.helioseasycontrols/README.md index 86ef6bbdd..eaaf7b393 100644 --- a/bundles/org.openhab.binding.modbus.helioseasycontrols/README.md +++ b/bundles/org.openhab.binding.modbus.helioseasycontrols/README.md @@ -29,7 +29,7 @@ The following channels are supported: | Channel | Channel Group | Description | Item Type | RW | | -------------------------------- | --------------- | -------------------------------------------------------------------------------------------------------------------------------- | ------------------------ | -- | | sysdate | general | The KWL's system date and time | DateTime | RW | -| summerWinter | general | Indicates if summertime or wintertime is active (OFF = wintertime, ON = summertime) | Switch | RW | +| summerWinter | general | Indicates if summertime or wintertime is active (0 = wintertime, 1 = summertime) | Number | RW | | autoSwUpdate | general | Indicates if automatic software updates are enable | Switch | RW | | accessHeliosPortal | general | Indicates if access to Helios portal is enabled | Switch | RW | | minFanStage | unitConfig | Minimum fan stage (0 or 1) (0, 1) | Number | RW | @@ -39,7 +39,6 @@ The following channels are supported: | humidityStopTime | humidityControl | Humidity stop time in hours (0-24) (0 - 24 h) | Number:Time | RW | | co2ControlSetValue | co2Control | CO2 control set value (in ppm) (300 - 2000 ppm) | Number:Dimensionless | RW | | co2ControlSteps | co2Control | CO2 control steps (in ppm) (50 - 400 ppm) | Number:Dimensionless | RW | -| vocControlStatus | vocControl | VOC control status (0 = off, 1 = stepped, 2 = stepless) | Number | RW | | vocControlSetValue | vocControl | VOC control set value (in ppm) (300 - 2000 ppm) | Number:Dimensionless | RW | | vocControlSteps | vocControl | VOC control steps (in ppm) (50 - 400 ppm) | Number:Dimensionless | RW | | comfortTemp | unitConfig | Comfort Temperature (10.0 - 25.0 °C) | Number:Temperature | RW | @@ -51,7 +50,7 @@ The following channels are supported: | standbyModeFanStage | operation | Standby mode fan stage (0 - 4) | Number | RW | | standbyModeRemainingTime | operation | Standby mode remaining time (0 - 180 min) | Number:Time | R | | standbyModeStatus | operation | Standby mode status | Switch | RW | -| operatingMode | operation | Operating mode (automatic/manual) (OFF = automatic, ON = manual) | Switch | RW | +| operatingMode | operation | Operating mode (automatic/manual) (0 = automatic, 1 = manual) | Number | RW | | fanStage | operation | Fan stage (0 - 4) | Number | RW | | percentageFanStage | operation | Fan stage in percent (0 - 100 %) | Number:Dimensionless | R | | temperatureOutsideAir | general | Ouside air temperature in °C (-27.0 - 9998.9 °C) | Number:Temperature | R | @@ -104,7 +103,7 @@ The following channels are supported: | holidayProgrammeActivationTime | operation | Holiday programme activation time in minutes (5 - 300 min) | Number:Time | RW | | runOnTimeVhzNhz | unitConfig | Stopping time preheater/afterheater in seconds (60 - 120 s) | Number:Time | RW | | errorOutputFunction | unitConfig | Error output function (collective error or just error) (1 = collective error, 2 = only error) | Number | RW | -| filterChange | unitConfig | Filter change | Switch | RW | +| filterChange | unitConfig | Filter change (0 = No, 1 = Yes) | Number | RW | | filterChangeInterval | unitConfig | Filter change interval in months (1 - 12) | Number | RW | | filterChangeRemainingTime | general | Filter change remaining time in minutes (1 - 55000 min) | Number:Time | R | | bypassRoomTemperature | unitConfig | Bypass room temperature in °C (10 - 40 °C) | Number:Temperature | RW | @@ -131,6 +130,7 @@ The following channels are supported: | bypassFrom | unitConfig | Bypass active from | DateTime | RW | | bypassTo | unitConfig | Bypass active to | DateTime | RW | + ## Thing Actions ### Reset Filter Change Timer @@ -227,6 +227,7 @@ The binding provides the following properties: | kwlFtfConfig7 | Humidity/temperature sensor configuration 7 (1 = only humidity, 2 = only temperature, 3 = combined) | | humidityControlStatus | Humidity control status (0 = off, 1 = stepped, 2 = stepless) | | co2ControlStatus | CO2 control status (0 = off, 1 = stepped, 2 = stepless) | +| vocControlStatus | VOC control status (0 = off, 1 = stepped, 2 = stepless) | | dateFormat | Date format (0 = dd.mm.yyyy, 1 = mm.dd.yyyy, 2 = yyyy.mm.dd) | | heatExchangerType | Heat exchanger type (0 = plastic, 1 = aluminium, 2 = enthalpy) | | serNo | Serial number | @@ -276,7 +277,6 @@ The binding provides the following properties: | sensorConfigKwlFtf8 | Sensor configuration (installed or not) KWL-FTF 8 (OFF = no sensor, ON = sensor installed) | - ## Full Example ### Thing Configuration diff --git a/bundles/org.openhab.binding.modbus.helioseasycontrols/src/main/java/org/openhab/binding/modbus/helioseasycontrols/internal/HeliosEasyControlsActions.java b/bundles/org.openhab.binding.modbus.helioseasycontrols/src/main/java/org/openhab/binding/modbus/helioseasycontrols/internal/HeliosEasyControlsActions.java index 8efc8bb17..d944c101f 100644 --- a/bundles/org.openhab.binding.modbus.helioseasycontrols/src/main/java/org/openhab/binding/modbus/helioseasycontrols/internal/HeliosEasyControlsActions.java +++ b/bundles/org.openhab.binding.modbus.helioseasycontrols/src/main/java/org/openhab/binding/modbus/helioseasycontrols/internal/HeliosEasyControlsActions.java @@ -51,7 +51,7 @@ public class HeliosEasyControlsActions implements ThingActions { handler.writeValue(variableName, "1"); } } catch (HeliosException e) { - logger.warn("Error executing action 'resetFilterChangeTimer': {}", e.getMessage()); + logger.warn("Error executing action triggering switch for variable {}: {}", variableName, e.getMessage()); } } diff --git a/bundles/org.openhab.binding.modbus.helioseasycontrols/src/main/java/org/openhab/binding/modbus/helioseasycontrols/internal/HeliosEasyControlsHandler.java b/bundles/org.openhab.binding.modbus.helioseasycontrols/src/main/java/org/openhab/binding/modbus/helioseasycontrols/internal/HeliosEasyControlsHandler.java index 4d0da544e..f15ba7041 100644 --- a/bundles/org.openhab.binding.modbus.helioseasycontrols/src/main/java/org/openhab/binding/modbus/helioseasycontrols/internal/HeliosEasyControlsHandler.java +++ b/bundles/org.openhab.binding.modbus.helioseasycontrols/src/main/java/org/openhab/binding/modbus/helioseasycontrols/internal/HeliosEasyControlsHandler.java @@ -96,16 +96,44 @@ public class HeliosEasyControlsHandler extends BaseThingHandler { // before reading from device private class BypassDate { + private final int[] MONTH_MAX_DAYS = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + // initialization to avoid issues when updating before all variables were read private int month = 1; private int day = 1; + public BypassDate() { + } + + public BypassDate(int day, int month) { + this.setDay(day); + this.setMonth(month); + } + public void setMonth(int month) { - this.month = month; + if (month < 1) { + this.month = 1; + } else if (month > 12) { + this.month = 12; + } else { + this.month = month; + } + } + + public int getMonth() { + return this.month; } public void setDay(int day) { - this.day = day; + if (day < 1) { + this.day = 1; + } else { + this.day = Math.min(day, MONTH_MAX_DAYS[month - 1]); + } + } + + public int getDay() { + return this.day; } public DateTimeType toDateTimeType() { @@ -551,11 +579,14 @@ public class HeliosEasyControlsHandler extends BaseThingHandler { } protected void setBypass(boolean from, int day, int month) { + BypassDate bypassDate = new BypassDate(day, month); try { this.writeValue(from ? HeliosEasyControlsBindingConstants.BYPASS_FROM_DAY - : HeliosEasyControlsBindingConstants.BYPASS_TO_DAY, Integer.toString(day)); - this.writeValue(from ? HeliosEasyControlsBindingConstants.BYPASS_FROM_MONTH - : HeliosEasyControlsBindingConstants.BYPASS_TO_MONTH, Integer.toString(month)); + : HeliosEasyControlsBindingConstants.BYPASS_TO_DAY, Integer.toString(bypassDate.getDay())); + this.writeValue( + from ? HeliosEasyControlsBindingConstants.BYPASS_FROM_MONTH + : HeliosEasyControlsBindingConstants.BYPASS_TO_MONTH, + Integer.toString(bypassDate.getMonth())); } catch (HeliosException e) { logger.warn("{} encountered Exception when trying to set bypass period: {}", HeliosEasyControlsHandler.class.getSimpleName(), e.getMessage());