]> git.basschouten.com Git - openhab-addons.git/commitdiff
[smartmeter] Fix trying to create channels from invalid data (#10008)
authorStefan Triller <t2000@users.noreply.github.com>
Wed, 3 Feb 2021 20:37:00 +0000 (21:37 +0100)
committerGitHub <noreply@github.com>
Wed, 3 Feb 2021 20:37:00 +0000 (21:37 +0100)
Fixes #6762

* Fix Unit tests
The method was used to create the pattern for a regex and for building
the channel id. I ave separated them now. At least the tests are green ;)

Signed-off-by: Stefan Triller <github@stefantriller.de>
bundles/org.openhab.binding.smartmeter/src/main/java/org/openhab/binding/smartmeter/SmartMeterBindingConstants.java
bundles/org.openhab.binding.smartmeter/src/main/java/org/openhab/binding/smartmeter/internal/iec62056/Iec62056_21SerialConnector.java

index 8738b747189b91683ed77f1d243726870761383b..de2b535b4441193061762fa84e52359998aef0fa 100644 (file)
@@ -36,14 +36,18 @@ public class SmartMeterBindingConstants {
     public static final String CONFIGURATION_CONVERSION = "conversionRatio";
     public static final String CONFIGURATION_CHANNEL_NEGATE = "negate";
     public static final String CHANNEL_PROPERTY_OBIS = "obis";
-    public static final String OBIS_PATTERN_CHANNELID = getObisChannelId(ObisCode.OBIS_PATTERN);
+    public static final String OBIS_PATTERN_CHANNELID = getObisChannelIdPattern(ObisCode.OBIS_PATTERN);
     /** Obis format */
     public static final String OBIS_FORMAT_MINIMAL = "%d-%d:%d.%d.%d";
     /** Obis format */
     public static final String OBIS_FORMAT = OBIS_FORMAT_MINIMAL + "*%d";
     public static final String CHANNEL_TYPE_METERREADER_OBIS = "channel-type:" + BINDING_ID + ":obis";
 
-    public static String getObisChannelId(String obis) {
+    public static String getObisChannelIdPattern(String obis) {
         return obis.replaceAll("\\.", "-").replaceAll(":|\\*", "_");
     }
+
+    public static String getObisChannelId(String obis) {
+        return getObisChannelIdPattern(obis).replaceAll("[^\\w-]", "");
+    }
 }
index 81f8ba40472ac6f2046407307e1d128c5527f0a2..f1a06905c8c89dbde88817da22ad3d94b04f6282 100644 (file)
@@ -100,6 +100,7 @@ public class Iec62056_21SerialConnector extends ConnectorBase<DataMessage> {
                         @Override
                         public void newDataMessage(@Nullable DataMessage dataMessage) {
                             logger.debug("Datamessage read: {}", dataMessage);
+                            emitter.onError(new IllegalArgumentException("Error while emitting dataMessage"));
                             emitter.onNext(dataMessage);
                         }