*
* @return stream of all unit strings
*/
- static Stream<String> getAllUnitStrings() {
- return DPT_UNIT_MAP.values().stream();
+ static Stream<Map.Entry<String, String>> getAllUnitStrings() {
+ return DPT_UNIT_MAP.entrySet().stream();
}
static {
for (Channel channel : getThing().getChannels()) {
KNXChannel knxChannel = KNXChannelFactory.createKnxChannel(channel);
- knxChannels.put(channel.getUID(), knxChannel);
- groupAddresses.addAll(knxChannel.getAllGroupAddresses());
if (knxChannel.getChannelType().startsWith("number")) {
// check if we need to update the accepted item-type
List<InboundSpec> inboundSpecs = knxChannel.getAllGroupAddresses().stream()
.map(knxChannel::getListenSpec).filter(Objects::nonNull).map(Objects::requireNonNull).toList();
+ if (inboundSpecs.isEmpty()) {
+ logger.warn("Skipping {}: group address / DPT not according to Group Address Notation",
+ channel.getUID());
+ continue;
+ }
String dpt = inboundSpecs.get(0).getDPT(); // there can be only one DPT on number channels
Unit<?> unit = UnitUtils.parseUnit(DPTUnits.getUnitForDpt(dpt));
modified = true;
}
}
+
+ // add channels only if they could be successfully processed
+ knxChannels.put(channel.getUID(), knxChannel);
+ groupAddresses.addAll(knxChannel.getAllGroupAddresses());
}
if (modified) {
import static org.junit.jupiter.api.Assertions.*;
+import java.util.Map;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.stream.IntStream;
assertNotEquals(DPTXlator64BitSigned.DPT_REACTIVE_ENERGY.getUnit(), Units.VAR_HOUR.toString());
}
- private static Stream<String> unitProvider() {
+ private static Stream<Map.Entry<String, String>> unitProvider() {
return DPTUnits.getAllUnitStrings();
}
@ParameterizedTest
@MethodSource("unitProvider")
- public void unitsValid(String unit) {
- String valueStr = "1 " + unit;
- QuantityType<?> value = new QuantityType<>(valueStr);
- Assertions.assertNotNull(value);
+ public void unitsValid(Map.Entry<String, String> unit) {
+ String valueStr = "1 " + unit.getValue();
+ try {
+ QuantityType<?> value = new QuantityType<>(valueStr);
+ Assertions.assertNotNull(value, "Failed to parse " + unit + "(result null)");
+ } catch (Exception e) {
+ fail("Failed to parse " + unit + ": " + e.getMessage());
+ }
}
private static Stream<byte[]> rgbValueProvider() {