Skip to content

Commit

Permalink
[knx] Upgrade Calimero to 2.6-rc1 (#16588)
Browse files Browse the repository at this point in the history
* [knx] Upgrade Calimero to 2.6-rc1
- Bugfixes and new subtypes for DPTs 20, 21, 22.
- Remove workarounds for issues in v2.5.1.

Signed-off-by: Holger Friedrich <[email protected]>
  • Loading branch information
holgerfriedrich authored Mar 31, 2024
1 parent df884ac commit 1dd8fd1
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 82 deletions.
18 changes: 10 additions & 8 deletions bundles/org.openhab.binding.knx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,29 +372,31 @@ Further DPTs and subtypes may be added later once implemented and released in th
|||
| 19.001 | DateTimeType (datetime) (DateTime) | Date and Time, year can be 1900..2155 |
|||
| 20.xxx | | Incomplete, only subtypes given below are supported; override with DPT5.010 if you need enum as DecimalType |
| 20.xxx | | Override with DPT5.010 if you need enum as DecimalType |
| 20.001-20.009 | StringType (string) | |
| 20.011-20.014 | StringType (string) | |
| 20.017 | StringType (string) | |
| 20.020-20.021 | StringType (string) | |
| 20.100-20.114 | StringType (string) | |
| 20.020-20.022 | StringType (string) | |
| 20.100-20.115 | StringType (string) | |
| 20.120-20.122 | StringType (string) | |
| 20.600-20.610 | StringType (string) | |
| 20.600-20.613 | StringType (string) | |
| 20.801-20.804 | StringType (string) | |
| 20.1000-20.1005 | StringType (string) | |
| 20.1200 | StringType (string) | |
| 20.1202 | StringType (string) | |
| 20.1202-20.1209 | StringType (string) | |
|||
| 21.xxx | | Incomplete, only subtypes given below are supported; override with DPT5.010 if you need bitset as DecimalType |
| 21.xxx | | Override with DPT5.010 if you need bitset as DecimalType |
| 21.001-20.002 | StringType (string) | |
| 21.100-20.106 | StringType (string) | |
| 21.601 | StringType (string) | |
| 21.1000-21.1002 | StringType (string) | |
| 21.1010 | StringType (string) | |
| 21.1200-21.1201 | StringType (string) | |
|||
| 22.xxx | | Incomplete, only subtypes given below are supported; override with DPT7.010 if you need bitset as DecimalType |
| 22.101 | StringType (string) | |
| 22.xxx | | Override with DPT7.010 if you need bitset as DecimalType |
| 22.100-22.101 | StringType (string) | |
| 22.1000 | StringType (string) | |
| 22.1010 | StringType (string) | |
|||
| 28.001 | StringType (string) | KNX representation is Null-terminated, do not include null characters |
|||
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.openhab.binding.knx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<dependency>
<groupId>com.github.calimero</groupId>
<artifactId>calimero-core</artifactId>
<version>2.5.1</version>
<version>2.6-rc1</version>
<scope>compile</scope>
<exclusions>
<exclusion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.Collections;
import java.util.HashMap;
import java.util.HexFormat;
import java.util.Map;
import java.util.Set;

Expand All @@ -25,7 +26,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import tuwien.auto.calimero.DataUnitBuilder;
import tuwien.auto.calimero.DeviceDescriptor;
import tuwien.auto.calimero.DeviceDescriptor.DD0;
import tuwien.auto.calimero.DeviceDescriptor.DD2;
Expand Down Expand Up @@ -279,7 +279,7 @@ private Map<String, String> readDeviceProperties(IndividualAddress address) thro
}

private @Nullable String toHex(byte @Nullable [] input, String separator) {
return input == null ? null : DataUnitBuilder.toHex(input, separator);
return input == null ? null : HexFormat.ofDelimiter(separator).formatHex(input);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private synchronized void startDiscovery() {

for (Result<SearchResponse> r : responses) {
@Nullable
SearchResponse response = r.getResponse();
SearchResponse response = r.response();
Map<ServiceFamily, Integer> services = response.getServiceFamilies().families();

if (services.containsKey(ServiceFamiliesDIB.ServiceFamily.Tunneling)
Expand All @@ -113,16 +113,16 @@ private synchronized void startDiscovery() {
.withLabel(response.getDevice().getName()).withProperty("serialNumber", serial)
.withProperty("type", "TUNNEL")
.withProperty("ipAddress",
"" + response.getControlEndpoint().getAddress().getHostAddress())
.withProperty("port", "" + response.getControlEndpoint().getPort())
"" + response.getControlEndpoint().endpoint().getAddress().getHostAddress())
.withProperty("port", "" + response.getControlEndpoint().endpoint().getPort())
.withRepresentationProperty("serialNumber").build());
}
if (services.containsKey(ServiceFamiliesDIB.ServiceFamily.Routing)) {
thingDiscovered(DiscoveryResultBuilder.create(new ThingUID(THING_TYPE_IP_BRIDGE, serial))
.withLabel(response.getDevice().getName() + " (router mode)")
.withProperty("serialNumber", serial + "-r").withProperty("type", "ROUTER")
.withProperty("ipAddress", "224.0.23.12")
.withProperty("port", "" + response.getControlEndpoint().getPort())
.withProperty("port", "" + response.getControlEndpoint().endpoint().getPort())
.withRepresentationProperty("serialNumber").build());
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ static Stream<Map.Entry<String, String>> getAllUnitStrings() {

// two byte unsigned (DPT 7)
DPT_UNIT_MAP.remove(DPTXlator2ByteUnsigned.DPT_VALUE_2_UCOUNT.getID()); // counts have no unit
DPT_UNIT_MAP.put(DPTXlator2ByteUnsigned.DPT_TIMEPERIOD_10.getID(), "ms"); // according to spec, it is ms
DPT_UNIT_MAP.put(DPTXlator2ByteUnsigned.DPT_TIMEPERIOD_100.getID(), "ms"); // according to spec, it is ms

// two byte signed (DPT 8)
DPT_UNIT_MAP.remove(DptXlator2ByteSigned.DptValueCount.getID()); // pulses have no unit
Expand All @@ -130,10 +128,8 @@ static Stream<Map.Entry<String, String>> getAllUnitStrings() {
DPT_UNIT_MAP.remove(DPTXlator4ByteSigned.DPT_COUNT.getID()); // counts have no unit

// four byte float (DPT 14)
DPT_UNIT_MAP.put(DPTXlator4ByteFloat.DPT_CONDUCTANCE.getID(), Units.SIEMENS.toString());
DPT_UNIT_MAP.put(DPTXlator4ByteFloat.DPT_ANGULAR_MOMENTUM.getID(),
Units.JOULE.multiply(Units.SECOND).toString());
DPT_UNIT_MAP.put(DPTXlator4ByteFloat.DPT_ACTIVITY.getID(), Units.BECQUEREL.toString());
DPT_UNIT_MAP.put(DPTXlator4ByteFloat.DPT_ELECTRICAL_CONDUCTIVITY.getID(),
Units.SIEMENS.divide(SIUnits.METRE).toString());
DPT_UNIT_MAP.put(DPTXlator4ByteFloat.DPT_TORQUE.getID(), Units.NEWTON.multiply(SIUnits.METRE).toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class ValueDecoder {
// omitted
public static final Pattern XYY_PATTERN = Pattern
.compile("(?:\\((?<x>\\d+(?:[,.]\\d+)?) (?<y>\\d+(?:[,.]\\d+)?)\\))?\\s*(?:(?<Y>\\d+(?:[,.]\\d+)?)\\s%)?");
public static final Pattern TSD_SEPARATOR = Pattern.compile("^[0-9](?<sep>[,\\.])[0-9][0-9][0-9].*");
public static final Pattern TSD_SEPARATOR = Pattern.compile("^[0-9]+(?<sep>[,\\.])[0-9][0-9][0-9].*");

private static boolean check235001(byte[] data) throws KNXException {
if (data.length != 6) {
Expand Down Expand Up @@ -214,10 +214,11 @@ private static boolean check23561001(byte[] data) throws KNXException {
int sep = java.lang.Math.max(value.indexOf(" % "), value.indexOf(" K "));
String time = value.substring(sep + 3);
Matcher mt = TSD_SEPARATOR.matcher(time);
if (mt.matches()) {
for (; mt.matches(); mt = TSD_SEPARATOR.matcher(time)) {
int dp = time.indexOf(mt.group("sep"));
value = value.substring(0, sep + dp + 3) + time.substring(dp + 1);
time = time.substring(0, dp) + time.substring(dp + 1);
}
value = value.substring(0, sep + 3) + time;
return StringType.valueOf(value.replace(',', '.').replace(". ", ", "));
case "232":
return handleDpt232(value, subType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import tuwien.auto.calimero.dptxlator.DPTXlator;
import tuwien.auto.calimero.dptxlator.DPTXlator1BitControlled;
import tuwien.auto.calimero.dptxlator.DPTXlator2ByteFloat;
import tuwien.auto.calimero.dptxlator.DPTXlator2ByteUnsigned;
import tuwien.auto.calimero.dptxlator.DPTXlator3BitControlled;
import tuwien.auto.calimero.dptxlator.DPTXlator4ByteFloat;
import tuwien.auto.calimero.dptxlator.DPTXlatorBoolean;
Expand Down Expand Up @@ -259,14 +258,6 @@ private static String handleNumericTypes(String dptId, String mainNumber, DPT dp
default:
return "1 " + valueDPT.getUpperValue();
}
case "7":
if (DPTXlator2ByteUnsigned.DPT_TIMEPERIOD_10.getID().equals(dptId)
|| DPTXlator2ByteUnsigned.DPT_TIMEPERIOD_100.getID().equals(dptId)) {
return bigDecimal.divide(BigDecimal.valueOf(1000)).stripTrailingZeros().toPlainString().replace('.',
((DecimalFormat) DecimalFormat.getInstance()).getDecimalFormatSymbols()
.getDecimalSeparator());
}
return bigDecimal.stripTrailingZeros().toPlainString();
case "18":
int intVal = bigDecimal.intValue();
if (intVal > 63) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,8 @@ public void dpt6Value() {
@Test
void testToDPT7ValueFromQuantityType() {
assertEquals("1000", ValueEncoder.encode(new QuantityType<>("1000 ms"), "7.002"));
// according to spec this should be 1000 for 7.003 and 7.004 - 1 is a workaround for Calimero 2.5.1
assertEquals("1", ValueEncoder.encode(new QuantityType<>("1000 ms"), "7.003"));
assertEquals("1", ValueEncoder.encode(new QuantityType<>("1000 ms"), "7.004"));
assertEquals("1000", ValueEncoder.encode(new QuantityType<>("1000 ms"), "7.003"));
assertEquals("1000", ValueEncoder.encode(new QuantityType<>("1000 ms"), "7.004"));
assertEquals("1", ValueEncoder.encode(new QuantityType<>("1000 ms"), "7.005"));
assertEquals("1", ValueEncoder.encode(new QuantityType<>("60 s"), "7.006"));
assertEquals("1", ValueEncoder.encode(new QuantityType<>("60 min"), "7.007"));
Expand Down Expand Up @@ -499,10 +498,8 @@ public void unitFixes() {

// two byte unsigned (DPT 7)
assertNotEquals("", DPTXlator2ByteUnsigned.DPT_VALUE_2_UCOUNT.getUnit()); // counts have no unit
assertNotEquals(DPTXlator2ByteUnsigned.DPT_TIMEPERIOD_10.getUnit(), "ms"); // according to spec, it is ms
assertNotEquals(DPTXlator2ByteUnsigned.DPT_TIMEPERIOD_100.getUnit(), "ms"); // according to spec, it is ms

// two byte signed (DPT 8, DPTXlator is missing in calimero 2.5-M1)
// two byte signed (DPT 8)
assertNotEquals("", DptXlator2ByteSigned.DptValueCount.getUnit()); // pulses have no unit

// 4 byte unsigned (DPT 12)
Expand Down
Loading

0 comments on commit 1dd8fd1

Please sign in to comment.