From 6abf41819fe84f50adf679009e9315f3f352581a Mon Sep 17 00:00:00 2001 From: docbender Date: Tue, 29 Sep 2020 13:21:54 +0200 Subject: [PATCH] Fix channel number address parser --- .../handler/simaticBridgeHandler.java | 1 + .../internal/simatic/SimaticChannel.java | 22 ++++++++++++++----- .../internal/simaticBindingConstants.java | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/org.openhab.binding.simatic/src/main/java/org/openhab/binding/simatic/internal/handler/simaticBridgeHandler.java b/org.openhab.binding.simatic/src/main/java/org/openhab/binding/simatic/internal/handler/simaticBridgeHandler.java index f7b5212..ee97ae6 100644 --- a/org.openhab.binding.simatic/src/main/java/org/openhab/binding/simatic/internal/handler/simaticBridgeHandler.java +++ b/org.openhab.binding.simatic/src/main/java/org/openhab/binding/simatic/internal/handler/simaticBridgeHandler.java @@ -250,6 +250,7 @@ public void handleRemoval() { */ public void updateConfig() { int stateChannelCount = 0; + channelCount = 0; for (Thing th : getThing().getThings()) { var h = ((SimaticGenericHandler) th.getHandler()); diff --git a/org.openhab.binding.simatic/src/main/java/org/openhab/binding/simatic/internal/simatic/SimaticChannel.java b/org.openhab.binding.simatic/src/main/java/org/openhab/binding/simatic/internal/simatic/SimaticChannel.java index f44960e..31e4c5a 100644 --- a/org.openhab.binding.simatic/src/main/java/org/openhab/binding/simatic/internal/simatic/SimaticChannel.java +++ b/org.openhab.binding.simatic/src/main/java/org/openhab/binding/simatic/internal/simatic/SimaticChannel.java @@ -109,13 +109,23 @@ public void clear() { address, channelType.getId()); return null; } - if (matcher.group(1) == null) { - return new SimaticPLCAddress(Integer.parseInt(matcher.group(6)), matcher.group(7), - Integer.parseInt(matcher.group(8)), - matcher.group(9) != null && !matcher.group(9).isEmpty()); + if (matcher.group(1) != null) { + return new SimaticPLCAddress(matcher.group(2), Integer.parseInt(matcher.group(3)), false); + } else if (matcher.group(4) != null) { + return new SimaticPLCAddress(matcher.group(5), Integer.parseInt(matcher.group(6)), + matcher.group(7) != null && !matcher.group(7).isEmpty()); + } else if (matcher.group(8) != null) { + return new SimaticPLCAddress(Integer.parseInt(matcher.group(9)), matcher.group(10), + Integer.parseInt(matcher.group(11)), false); + } else if (matcher.group(12) != null) { + return new SimaticPLCAddress(Integer.parseInt(matcher.group(13)), matcher.group(14), + Integer.parseInt(matcher.group(15)), + matcher.group(16) != null && !matcher.group(16).isEmpty()); } else { - return new SimaticPLCAddress(matcher.group(2), Integer.parseInt(matcher.group(3)), - matcher.group(4) != null && !matcher.group(4).isEmpty()); + error = String.format( + "Unsupported address '%s' for typeID=%s. Supported types B,W,D. Address example IB10, MW100, DB1.DBD0, DB1.DBD0F", + address, channelType.getId()); + return null; } case SimaticBindingConstants.CHANNEL_STRING: matcher = stringAddressPattern.matcher(address); diff --git a/org.openhab.binding.simatic/src/main/java/org/openhab/binding/simatic/internal/simaticBindingConstants.java b/org.openhab.binding.simatic/src/main/java/org/openhab/binding/simatic/internal/simaticBindingConstants.java index 0c8f818..aa8b47d 100644 --- a/org.openhab.binding.simatic/src/main/java/org/openhab/binding/simatic/internal/simaticBindingConstants.java +++ b/org.openhab.binding.simatic/src/main/java/org/openhab/binding/simatic/internal/simaticBindingConstants.java @@ -25,7 +25,7 @@ @NonNullByDefault public class SimaticBindingConstants { - public static final String VERSION = "3.0.0-beta.2"; + public static final String VERSION = "3.0.0-beta.3"; private static final String BINDING_ID = "simatic";