]> git.basschouten.com Git - openhab-addons.git/commitdiff
[knx] Fix DPT 243.600 and 249.600 when time>=1000s (#16481)
authorHolger Friedrich <mail@holger-friedrich.de>
Mon, 4 Mar 2024 17:56:34 +0000 (18:56 +0100)
committerGitHub <noreply@github.com>
Mon, 4 Mar 2024 17:56:34 +0000 (18:56 +0100)
* [knx] Fix DPT 243.600 and 249.600 when time>=1000s

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/ValueDecoder.java
bundles/org.openhab.binding.knx/src/test/java/org/openhab/binding/knx/internal/itests/Back2BackTest.java

index 13376f1d2f92995ff65f12b284b90bb144a9057f..1d3109b8a50f3ef1cb05cb4463044e81f66086d4 100644 (file)
@@ -80,6 +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].*");
 
     private static boolean check235001(byte[] data) throws KNXException {
         if (data.length != 6) {
@@ -208,6 +209,15 @@ public class ValueDecoder {
                     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);
index 48424413d3e44e3abf721c6fc898a1aec26eb851..3d96e7bcfa16c53cabc9b5f14eed3ee40040cdda 100644 (file)
@@ -930,9 +930,18 @@ public class Back2BackTest {
         // 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"));