[smartmeter] Fix trying to create channels from invalid data (#10008)

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>
pull/10046/head
Stefan Triller 2021-02-03 21:37:00 +01:00 committed by GitHub
parent 570f86d043
commit bc5ffb26e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View 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-]", "");
}
}

View 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);
}