[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 <mail@holger-friedrich.de>
This commit is contained in:
Holger Friedrich 2024-03-04 18:56:34 +01:00 committed by GitHub
parent fdb2bba7a6
commit 2c1a08679a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 0 deletions

View 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);

View 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"));