From: boehan Date: Wed, 26 May 2021 19:12:15 +0000 (+0200) Subject: [comfoair] fix data handling for restricted devices (#10685) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=19029b73589fecbc1e4eb0d1979b880ef4243edc;p=openhab-addons.git [comfoair] fix data handling for restricted devices (#10685) Signed-off-by: Hans Böhm --- diff --git a/bundles/org.openhab.binding.comfoair/README.md b/bundles/org.openhab.binding.comfoair/README.md index f5b96fe6c8..0965ddcb9e 100644 --- a/bundles/org.openhab.binding.comfoair/README.md +++ b/bundles/org.openhab.binding.comfoair/README.md @@ -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 diff --git a/bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/ComfoAirBindingConstants.java b/bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/ComfoAirBindingConstants.java index e031e2d038..45d2264f89 100644 --- a/bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/ComfoAirBindingConstants.java +++ b/bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/ComfoAirBindingConstants.java @@ -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 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"; diff --git a/bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/ComfoAirHandler.java b/bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/ComfoAirHandler.java index c384c6626a..c356d9fa21 100644 --- a/bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/ComfoAirHandler.java +++ b/bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/ComfoAirHandler.java @@ -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 affectedReadCommands; + private Set linkedChannels; - public AffectedItemsUpdateThread(Collection affectedReadCommands) { + public AffectedItemsUpdateThread(Collection affectedReadCommands, Set 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); + } } } } diff --git a/bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/ComfoAirHandlerFactory.java b/bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/ComfoAirHandlerFactory.java index 51be030866..f0822918c5 100644 --- a/bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/ComfoAirHandlerFactory.java +++ b/bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/ComfoAirHandlerFactory.java @@ -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 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); } diff --git a/bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/ComfoAirSerialConnector.java b/bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/ComfoAirSerialConnector.java index 69945f3b8b..f75ea88adf 100644 --- a/bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/ComfoAirSerialConnector.java +++ b/bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/ComfoAirSerialConnector.java @@ -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; diff --git a/bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/datatypes/DataTypeMessage.java b/bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/datatypes/DataTypeMessage.java index fa7f5f130d..6de5be2bfc 100644 --- a/bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/datatypes/DataTypeMessage.java +++ b/bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/datatypes/DataTypeMessage.java @@ -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 index 0000000000..7210e8a486 --- /dev/null +++ b/bundles/org.openhab.binding.comfoair/src/main/resources/OH-INF/config/config.xml @@ -0,0 +1,20 @@ + + + + + + + serial-port + Serial port that the ComfoAir is connected to + + + + Refresh interval in seconds + 60 + + + diff --git a/bundles/org.openhab.binding.comfoair/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.comfoair/src/main/resources/OH-INF/thing/thing-types.xml index d600617279..ec2b1203db 100644 --- a/bundles/org.openhab.binding.comfoair/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.comfoair/src/main/resources/OH-INF/thing/thing-types.xml @@ -41,18 +41,32 @@ - - - - serial-port - Serial port that the ComfoAir is connected to - - - - Refresh interval in seconds - 60 - - + + + + + + + Provides a generic access to a Zehnder WHR930 ventilation device + + + + + + + + + + + + + + + + + + + @@ -82,6 +96,23 @@ + + + + + + + + + + + + + + + + + @@ -103,6 +134,21 @@ + + + + + + + + + + + + + + + @@ -117,6 +163,19 @@ + + + + + + + + + + + + + @@ -189,6 +248,18 @@ + + + + + + + + + + + + @@ -205,6 +276,18 @@ + + + + + + + + + + + + @@ -219,6 +302,18 @@ + + + + + + + + + + + + @@ -233,6 +328,17 @@ + + + + + + + + + + +