]> git.basschouten.com Git - openhab-addons.git/commitdiff
[comfoair] fix data handling for restricted devices (#10685)
authorboehan <boehan@users.noreply.github.com>
Wed, 26 May 2021 19:12:15 +0000 (21:12 +0200)
committerGitHub <noreply@github.com>
Wed, 26 May 2021 19:12:15 +0000 (21:12 +0200)
Signed-off-by: Hans Böhm <h.boehm@gmx.at>
bundles/org.openhab.binding.comfoair/README.md
bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/ComfoAirBindingConstants.java
bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/ComfoAirHandler.java
bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/ComfoAirHandlerFactory.java
bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/ComfoAirSerialConnector.java
bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/datatypes/DataTypeMessage.java
bundles/org.openhab.binding.comfoair/src/main/resources/OH-INF/config/config.xml [new file with mode: 0644]
bundles/org.openhab.binding.comfoair/src/main/resources/OH-INF/thing/thing-types.xml

index f5b96fe6c8e3399220a9ebaa9b58e121815a1d5a..0965ddcb9eb8632f845c0294326673b9d5db8845 100644 (file)
@@ -27,11 +27,14 @@ sudo usermod -a -G dialout openhab
 
 ## Supported Things
 
-Only a single generic thing type is supported by the binding:
-
-|Thing Type ID |Description                                                          |
-|--------------|---------------------------------------------------------------------|
-|comfoair      |A ComfoAir ventilation system connected via RS232 serial connection. |
+The binding supports thing types for different device types.
+They only differ in the available channels, where the generic *comfoair* thing type supports all available channels.
+If there is no thing type that matches your specific device you can safely choose the *comfoair* type.
+
+|Thing Type ID |Description                                                                  |
+|--------------|-----------------------------------------------------------------------------|
+|comfoair      |A ComfoAir ventilation system connected via RS232 serial connection.         |
+|WHR930        |Thing type restricted to the data points available for the StorkAir WHR930.  |
 
 ## Discovery
 
index e031e2d038de04bf288f92be41146fb42ec3c97e..45d2264f89ef3b60f63c8b4c30352bf6ee66d67f 100644 (file)
@@ -12,6 +12,8 @@
  */
 package org.openhab.binding.comfoair.internal;
 
+import java.util.Set;
+
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.openhab.core.thing.ThingTypeUID;
 
@@ -27,6 +29,10 @@ public class ComfoAirBindingConstants {
     private static final String BINDING_ID = "comfoair";
 
     public static final ThingTypeUID THING_TYPE_COMFOAIR_GENERIC = new ThingTypeUID(BINDING_ID, "comfoair");
+    public static final ThingTypeUID THING_TYPE_COMFOAIR_WHR930 = new ThingTypeUID(BINDING_ID, "WHR930");
+
+    public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_COMFOAIR_GENERIC,
+            THING_TYPE_COMFOAIR_WHR930);
 
     // Thing properties
     public static final String PROPERTY_SOFTWARE_MAIN_VERSION = "SOFTWARE_VERSION_MAIN";
index c384c6626a229c8ebcbed5bfefc7d83f289f0855..c356d9fa2139eec610b4046a1e15ddeb40fe6811 100644 (file)
@@ -88,7 +88,7 @@ public class ComfoAirHandler extends BaseThingHandler {
                                 .getAffectedReadCommands(channelId, keysToUpdate);
 
                         if (!affectedReadCommands.isEmpty()) {
-                            Runnable updateThread = new AffectedItemsUpdateThread(affectedReadCommands);
+                            Runnable updateThread = new AffectedItemsUpdateThread(affectedReadCommands, keysToUpdate);
                             affectedItemsPoller = scheduler.schedule(updateThread, 3, TimeUnit.SECONDS);
                         }
                     } else {
@@ -273,7 +273,8 @@ public class ComfoAirHandler extends BaseThingHandler {
                     }
                     if (value instanceof UnDefType) {
                         if (logger.isWarnEnabled()) {
-                            logger.warn("unexpected value for DATA: {}", ComfoAirSerialConnector.dumpData(response));
+                            logger.warn("unexpected value for key '{}'. DATA: {}", commandKey,
+                                    ComfoAirSerialConnector.dumpData(response));
                         }
                     }
                     return value;
@@ -320,9 +321,11 @@ public class ComfoAirHandler extends BaseThingHandler {
     private class AffectedItemsUpdateThread implements Runnable {
 
         private Collection<ComfoAirCommand> affectedReadCommands;
+        private Set<String> linkedChannels;
 
-        public AffectedItemsUpdateThread(Collection<ComfoAirCommand> affectedReadCommands) {
+        public AffectedItemsUpdateThread(Collection<ComfoAirCommand> affectedReadCommands, Set<String> linkedChannels) {
             this.affectedReadCommands = affectedReadCommands;
+            this.linkedChannels = linkedChannels;
         }
 
         @Override
@@ -334,8 +337,10 @@ public class ComfoAirHandler extends BaseThingHandler {
 
                     for (ComfoAirCommandType commandType : commandTypes) {
                         String commandKey = commandType.getKey();
-                        State state = sendCommand(readCommand, commandKey);
-                        updateState(commandKey, state);
+                        if (linkedChannels.contains(commandKey)) {
+                            State state = sendCommand(readCommand, commandKey);
+                            updateState(commandKey, state);
+                        }
                     }
                 }
             }
index 51be0308663fb0240011dc6ef24882239bcf376b..f0822918c55a61e8657df67300bfa41540c34ece 100644 (file)
@@ -12,9 +12,6 @@
  */
 package org.openhab.binding.comfoair.internal;
 
-import java.util.Collections;
-import java.util.Set;
-
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.core.io.transport.serial.SerialPortManager;
@@ -36,9 +33,6 @@ import org.osgi.service.component.annotations.Reference;
 @Component(configurationPid = "binding.comfoair", service = ThingHandlerFactory.class)
 public class ComfoAirHandlerFactory extends BaseThingHandlerFactory {
 
-    private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
-            .singleton(ComfoAirBindingConstants.THING_TYPE_COMFOAIR_GENERIC);
-
     private @NonNullByDefault({}) SerialPortManager serialPortManager;
 
     @Reference
@@ -52,14 +46,15 @@ public class ComfoAirHandlerFactory extends BaseThingHandlerFactory {
 
     @Override
     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
-        return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
+        return ComfoAirBindingConstants.SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
     }
 
     @Override
     protected @Nullable ThingHandler createHandler(Thing thing) {
         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
 
-        if (ComfoAirBindingConstants.THING_TYPE_COMFOAIR_GENERIC.equals(thingTypeUID)) {
+        if (ComfoAirBindingConstants.THING_TYPE_COMFOAIR_GENERIC.equals(thingTypeUID)
+                || ComfoAirBindingConstants.THING_TYPE_COMFOAIR_WHR930.equals(thingTypeUID)) {
             return new ComfoAirHandler(thing, serialPortManager);
         }
 
index 69945f3b8b00337cdfae3091b3783270d63de1b6..f75ea88adfeda58a2967b9bdc220bfb4e3212c08 100644 (file)
@@ -511,7 +511,9 @@ public class ComfoAirSerialConnector {
 
                     if (preRequestData.length > 0 && newRequestData.length <= preRequestData.length) {
                         System.arraycopy(preRequestData, 0, newRequestData, 0, 6);
-                        System.arraycopy(preRequestData, 10, newRequestData, 6, newRequestData.length - 6);
+                        if (preRequestData.length > 10) {
+                            System.arraycopy(preRequestData, 10, newRequestData, 6, newRequestData.length - 6);
+                        }
                         newRequestData[dataPosition] = requestValue;
                     } else {
                         return ComfoAirCommandType.Constants.EMPTY_INT_ARRAY;
index fa7f5f130da8b723409de3829dca573eb828927b..6de5be2bfca833f9fcc68db4572206b26ffc5558 100644 (file)
@@ -50,8 +50,8 @@ public class DataTypeMessage implements ComfoAirDataType {
             if (readReplyDataPos != null) {
                 int errorAlo = data[readReplyDataPos[0]];
                 int errorE = data[readReplyDataPos[1]];
-                int errorEA = data[readReplyDataPos[2]];
-                int errorAhi = data[readReplyDataPos[3]];
+                int errorEA = (data.length > 9) ? data[readReplyDataPos[2]] : -1;
+                int errorAhi = (data.length > 9) ? data[readReplyDataPos[3]] : -1;
 
                 StringBuilder errorCode = new StringBuilder();
 
diff --git a/bundles/org.openhab.binding.comfoair/src/main/resources/OH-INF/config/config.xml b/bundles/org.openhab.binding.comfoair/src/main/resources/OH-INF/config/config.xml
new file mode 100644 (file)
index 0000000..7210e8a
--- /dev/null
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<config-description:config-descriptions
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:config-description="https://openhab.org/schemas/config-description/v1.0.0"
+       xsi:schemaLocation="https://openhab.org/schemas/config-description/v1.0.0
+       https://openhab.org/schemas/config-description-1.0.0.xsd">
+
+       <config-description uri="thing-type:comfoair:serial">
+               <parameter name="serialPort" type="text" required="true">
+                       <label>Serial Port</label>
+                       <context>serial-port</context>
+                       <description>Serial port that the ComfoAir is connected to</description>
+               </parameter>
+               <parameter name="refreshInterval" type="integer" max="65535" min="10" unit="s" required="false">
+                       <label>Refresh Interval</label>
+                       <description>Refresh interval in seconds</description>
+                       <default>60</default>
+               </parameter>
+       </config-description>
+</config-description:config-descriptions>
index d600617279ba317fd9859bd0afff479908198b0d..ec2b1203dbca64ec945297ed2bf30a5f69d65324 100644 (file)
                        <channel-group id="resets" typeId="resets"/>
                </channel-groups>
 
-               <config-description>
-                       <parameter name="serialPort" type="text" required="true">
-                               <label>Serial Port</label>
-                               <context>serial-port</context>
-                               <description>Serial port that the ComfoAir is connected to</description>
-                       </parameter>
-                       <parameter name="refreshInterval" type="integer" max="65535" min="10" unit="s" required="false">
-                               <label>Refresh Interval</label>
-                               <description>Refresh interval in seconds</description>
-                               <default>60</default>
-                       </parameter>
-               </config-description>
+               <config-description-ref uri="thing-type:comfoair:serial"/>
+
+       </thing-type>
+
+       <thing-type id="WHR930">
+               <label>Zehnder WHR930 Ventilation System</label>
+               <description>Provides a generic access to a Zehnder WHR930 ventilation device</description>
+
+               <channel-groups>
+                       <channel-group id="bindingControl" typeId="bindingControl"/>
+                       <channel-group id="ventilation" typeId="ventilation_WHR930"/>
+                       <channel-group id="temperatures" typeId="temperatures_WHR930"/>
+                       <channel-group id="times" typeId="times_WHR930"/>
+                       <channel-group id="bypass" typeId="bypass"/>
+                       <channel-group id="preheater" typeId="preheater"/>
+                       <channel-group id="options" typeId="options_WHR930"/>
+                       <channel-group id="menuP1" typeId="menuP1_WHR930"/>
+                       <channel-group id="menuP2" typeId="menuP2_WHR930"/>
+                       <channel-group id="menuP9" typeId="menuP9_WHR930"/>
+                       <channel-group id="inputs" typeId="inputs"/>
+                       <channel-group id="analogRF" typeId="analogRF"/>
+                       <channel-group id="errors" typeId="errors"/>
+                       <channel-group id="resets" typeId="resets"/>
+               </channel-groups>
+
+               <config-description-ref uri="thing-type:comfoair:serial"/>
 
        </thing-type>
 
                </channels>
        </channel-group-type>
 
+       <channel-group-type id="ventilation_WHR930">
+               <label>Ventilation Values</label>
+               <channels>
+                       <channel id="fanLevel" typeId="fan_evel"/>
+                       <channel id="fanOut0" typeId="fan_out_0"/>
+                       <channel id="fanOut1" typeId="fan_out_1"/>
+                       <channel id="fanOut2" typeId="fan_out_2"/>
+                       <channel id="fanIn0" typeId="fan_in_0"/>
+                       <channel id="fanIn1" typeId="fan_in_1"/>
+                       <channel id="fanIn2" typeId="fan_in_2"/>
+                       <channel id="fanInPercent" typeId="fan_in_percent"/>
+                       <channel id="fanOutPercent" typeId="fan_out_percent"/>
+                       <channel id="fanInRPM" typeId="fan_in_RPM"/>
+                       <channel id="fanOutRPM" typeId="fan_out_RPM"/>
+               </channels>
+       </channel-group-type>
+
        <channel-group-type id="temperatures">
                <label>Temperature Values</label>
                <channels>
                </channels>
        </channel-group-type>
 
+       <channel-group-type id="temperatures_WHR930">
+               <label>Temperature Values</label>
+               <channels>
+                       <channel id="targetTemperature" typeId="target_temperature"/>
+                       <channel id="outdoorTemperatureIn" typeId="outdoor_temperature_in"/>
+                       <channel id="outdoorTemperatureOut" typeId="outdoor_temperature_out"/>
+                       <channel id="indoorTemperatureIn" typeId="indoor_temperature_in"/>
+                       <channel id="indoorTemperatureOut" typeId="indoor_temperature_out"/>
+                       <channel id="isT1Sensor" typeId="is_T1_sensor"/>
+                       <channel id="isT2Sensor" typeId="is_T2_sensor"/>
+                       <channel id="isT3Sensor" typeId="is_T3_sensor"/>
+                       <channel id="isT4Sensor" typeId="is_T4_sensor"/>
+               </channels>
+       </channel-group-type>
+
        <channel-group-type id="times">
                <label>Uptimes</label>
                <channels>
                </channels>
        </channel-group-type>
 
+       <channel-group-type id="times_WHR930">
+               <label>Uptimes</label>
+               <channels>
+                       <channel id="level0Time" typeId="level0_time"/>
+                       <channel id="level1Time" typeId="level1_time"/>
+                       <channel id="level2Time" typeId="level2_time"/>
+                       <channel id="freezeTime" typeId="freeze_time"/>
+                       <channel id="preheaterTime" typeId="preheater_time"/>
+                       <channel id="bypassTime" typeId="bypass_time"/>
+                       <channel id="filterHours" typeId="filter_hours"/>
+               </channels>
+       </channel-group-type>
+
        <channel-group-type id="bypass">
                <label>Bypass Values</label>
                <channels>
                </channels>
        </channel-group-type>
 
+       <channel-group-type id="options_WHR930">
+               <label>Option Settings</label>
+               <channels>
+                       <channel id="isPreheater" typeId="is_preheater"/>
+                       <channel id="isBypass" typeId="is_bypass"/>
+                       <channel id="recuType" typeId="recu_type"/>
+                       <channel id="recuSize" typeId="recu_size"/>
+                       <channel id="isChimney" typeId="is_chimney"/>
+                       <channel id="isEnthalpy" typeId="is_enthalpy"/>
+               </channels>
+       </channel-group-type>
+
        <channel-group-type id="menuP1">
                <label>Menu P1: Control States</label>
                <channels>
                </channels>
        </channel-group-type>
 
+       <channel-group-type id="menuP1_WHR930">
+               <label>Menu P1: Control States</label>
+               <channels>
+                       <channel id="menu21Mode" typeId="menu21_mode"/>
+                       <channel id="menu22Mode" typeId="menu22_mode"/>
+                       <channel id="menu23Mode" typeId="menu23_mode"/>
+                       <channel id="menu24Mode" typeId="menu24_mode"/>
+                       <channel id="menu25Mode" typeId="menu25_mode"/>
+                       <channel id="menu26Mode" typeId="menu26_mode"/>
+               </channels>
+       </channel-group-type>
+
        <channel-group-type id="menuP2">
                <label>Menu P2: Delay Settings</label>
                <channels>
                </channels>
        </channel-group-type>
 
+       <channel-group-type id="menuP2_WHR930">
+               <label>Menu P2: Delay Settings</label>
+               <channels>
+                       <channel id="bathroomStartDelay" typeId="bathroom_start_delay"/>
+                       <channel id="bathroomEndDelay" typeId="bathroom_end_delay"/>
+                       <channel id="L1EndDelay" typeId="L1_end_delay"/>
+                       <channel id="filterWeeks" typeId="filter_weeks"/>
+                       <channel id="RFShortDelay" typeId="RF_short_delay"/>
+                       <channel id="RFLongDelay" typeId="RF_long_delay"/>
+               </channels>
+       </channel-group-type>
+
        <channel-group-type id="menuP9">
                <label>Menu P9: Option Control States</label>
                <channels>
                </channels>
        </channel-group-type>
 
+       <channel-group-type id="menuP9_WHR930">
+               <label>Menu P9: Option Control States</label>
+               <channels>
+                       <channel id="chimneyState" typeId="chimney_state"/>
+                       <channel id="bypassState" typeId="bypass_state"/>
+                       <channel id="vControlState" typeId="v_control_state"/>
+                       <channel id="frostState" typeId="frost_state"/>
+                       <channel id="enthalpyState" typeId="enthalpy_state"/>
+               </channels>
+       </channel-group-type>
+
        <channel-group-type id="inputs">
                <label>Inputs</label>
                <channels>