From 2c1a08679a57ccd50eff3c621426e95c1ca7d6d1 Mon Sep 17 00:00:00 2001 From: Holger Friedrich Date: Mon, 4 Mar 2024 18:56:34 +0100 Subject: [PATCH] [knx] Fix DPT 243.600 and 249.600 when time>=1000s (#16481) * [knx] Fix DPT 243.600 and 249.600 when time>=1000s Signed-off-by: Holger Friedrich --- .../openhab/binding/knx/internal/dpt/ValueDecoder.java | 10 ++++++++++ .../binding/knx/internal/itests/Back2BackTest.java | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/ValueDecoder.java b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/ValueDecoder.java index 13376f1d2f929..1d3109b8a50f3 100644 --- a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/ValueDecoder.java +++ b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/ValueDecoder.java @@ -80,6 +80,7 @@ public class ValueDecoder { // omitted public static final Pattern XYY_PATTERN = Pattern .compile("(?:\\((?\\d+(?:[,.]\\d+)?) (?\\d+(?:[,.]\\d+)?)\\))?\\s*(?:(?\\d+(?:[,.]\\d+)?)\\s%)?"); + public static final Pattern TSD_SEPARATOR = Pattern.compile("^[0-9](?[,\\.])[0-9][0-9][0-9].*"); private static boolean check235001(byte[] data) throws KNXException { if (data.length != 6) { @@ -208,6 +209,15 @@ private static boolean check23561001(byte[] data) throws KNXException { return StringType.valueOf(value); case "243": // color translation, fix regional case "249": // settings + // workaround for different number formats, this is to fix time>=1000s: + // time is last block and may contain . and , + 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()) { + int dp = time.indexOf(mt.group("sep")); + value = value.substring(0, sep + dp + 3) + time.substring(dp + 1); + } return StringType.valueOf(value.replace(',', '.').replace(". ", ", ")); case "232": return handleDpt232(value, subType); diff --git a/bundles/org.openhab.binding.knx/src/test/java/org/openhab/binding/knx/internal/itests/Back2BackTest.java b/bundles/org.openhab.binding.knx/src/test/java/org/openhab/binding/knx/internal/itests/Back2BackTest.java index 48424413d3e44..3d96e7bcfa16c 100644 --- a/bundles/org.openhab.binding.knx/src/test/java/org/openhab/binding/knx/internal/itests/Back2BackTest.java +++ b/bundles/org.openhab.binding.knx/src/test/java/org/openhab/binding/knx/internal/itests/Back2BackTest.java @@ -930,9 +930,18 @@ void testColorTransitionDpts() { // time(2) y(2) x(2), %brightness(1), flags(1) helper("243.600", new byte[] { 0, 5, 0x7F, 0, (byte) 0xfe, 0, 42, 3 }, new StringType("(0.9922, 0.4961) 16.5 % 0.5 s")); + helper("243.600", new byte[] { (byte) 0x02, (byte) 0x00, 0x7F, 0, (byte) 0xfe, 0, 42, 3 }, + new StringType("(0.9922, 0.4961) 16.5 % 51.2 s")); + helper("243.600", new byte[] { (byte) 0x40, (byte) 0x00, 0x7F, 0, (byte) 0xfe, 0, 42, 3 }, + new StringType("(0.9922, 0.4961) 16.5 % 1638.4 s")); + helper("243.600", new byte[] { (byte) 0xff, (byte) 0xff, 0x7F, 0, (byte) 0xfe, 0, 42, 3 }, + new StringType("(0.9922, 0.4961) 16.5 % 6553.5 s")); // DPT 249.600 DPT_Brightness_Colour_Temperature_Transition // time(2) colortemp(2), brightness(1), flags(1) helper("249.600", new byte[] { 0, 5, 0, 40, 127, 7 }, new StringType("49.8 % 40 K 0.5 s")); + helper("249.600", new byte[] { (byte) 0xff, (byte) 0xfa, 0, 40, 127, 7 }, new StringType("49.8 % 40 K 6553 s")); + helper("249.600", new byte[] { (byte) 0xff, (byte) 0xff, 0, 40, 127, 7 }, + new StringType("49.8 % 40 K 6553.5 s")); // DPT 250.600 DPT_Brightness_Colour_Temperature_Control // cct(1) cb(1) flags(1) helper("250.600", new byte[] { 0x0f, 0x0e, 3 }, new StringType("CT increase 7 steps BRT increase 6 steps"));