[dsmr] Fix handling problem reading gasmeter (#9736)
* [dsmr] Fix handling problem reading gasmeter The gasmeter seem to return an invalid date value in some cases. Possible problems with the meter. This however caused the whole meter readings to be ignored, while it should only ignore the single problem value. Signed-off-by: Hilbrand Bouwkamp <hilbrand@h72.nl> * [dsmr] Make eclipse happy again. Don't ask... Signed-off-by: Hilbrand Bouwkamp <hilbrand@h72.nl> * [dsmr] Removed sat warnings Removed usage of apache library and added NonNullByDefault to test classes.. Signed-off-by: Hilbrand Bouwkamp <hilbrand@h72.nl>
This commit is contained in:
committed by
GitHub
parent
3557094c13
commit
3f0c0ebf1f
@@ -12,8 +12,6 @@
|
||||
*/
|
||||
package org.openhab.binding.dsmr.internal.device;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
/**
|
||||
* Class describing the DSMR bridge user configuration
|
||||
*
|
||||
@@ -60,7 +58,8 @@ public class DSMRDeviceConfiguration {
|
||||
* @return true if serial port settings are all set.
|
||||
*/
|
||||
public boolean isSerialFixedSettings() {
|
||||
return baudrate > 0 && databits > 0 && !StringUtils.isBlank(parity) && !StringUtils.isBlank(stopbits);
|
||||
return baudrate > 0 && databits > 0 && !(parity != null && parity.isBlank())
|
||||
&& !(stopbits != null && stopbits.isBlank());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -35,6 +36,10 @@ import org.slf4j.LoggerFactory;
|
||||
class CosemDate extends CosemValueDescriptor<DateTimeType> {
|
||||
|
||||
public static final CosemDate INSTANCE = new CosemDate("timestamp");
|
||||
/*
|
||||
* Some meters can return the following value when something is wrong.
|
||||
*/
|
||||
public static final String INVALID_METER_VALUE = "632525252525W";
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(CosemDate.class);
|
||||
|
||||
@@ -102,8 +107,16 @@ class CosemDate extends CosemValueDescriptor<DateTimeType> {
|
||||
if (m.matches()) {
|
||||
logger.trace("{} matches pattern: {}", cosemValue, cosemDateFormat.pattern);
|
||||
|
||||
LocalDateTime localDateTime = LocalDateTime.parse(m.group(1), cosemDateFormat.formatter);
|
||||
return new DateTimeType(ZonedDateTime.of(localDateTime, ZoneId.systemDefault()));
|
||||
try {
|
||||
LocalDateTime localDateTime = LocalDateTime.parse(m.group(1), cosemDateFormat.formatter);
|
||||
return new DateTimeType(ZonedDateTime.of(localDateTime, ZoneId.systemDefault()));
|
||||
} catch (DateTimeParseException e) {
|
||||
if (INVALID_METER_VALUE.equals(cosemValue)) {
|
||||
throw new ParseException(
|
||||
"Cosem value: '" + cosemValue + "' might indicate something is wrong with the meter.",
|
||||
0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new ParseException("Cosem value: '" + cosemValue + "' is not a known CosemDate string", 0);
|
||||
|
||||
@@ -12,8 +12,12 @@
|
||||
*/
|
||||
package org.openhab.binding.dsmr.internal.discovery;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@@ -143,10 +147,9 @@ public class DSMRMeterDiscoveryService extends DSMRDiscoveryService implements P
|
||||
.map(Thing::getHandler)
|
||||
.filter(DSMRMeterHandler.class::isInstance)
|
||||
.map(DSMRMeterHandler.class::cast)
|
||||
.map(h -> h == null ? null : h.getMeterDescriptor())
|
||||
.map(d -> Optional.ofNullable(d == null ? null : d.getMeterType()))
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.map(DSMRMeterHandler::getMeterDescriptor)
|
||||
.filter(Objects::nonNull)
|
||||
.map(d -> d.getMeterType())
|
||||
.collect(Collectors.toSet());
|
||||
// @formatter:on
|
||||
// Create list of all configured meters that are not in the detected list. If not empty meters might not be
|
||||
|
||||
Reference in New Issue
Block a user