Skip to content

Commit

Permalink
[knx] Fix DPT 243.600 and 249.600 when time>=1000s (#16481)
Browse files Browse the repository at this point in the history
* [knx] Fix DPT 243.600 and 249.600 when time>=1000s

Signed-off-by: Holger Friedrich <[email protected]>
  • Loading branch information
holgerfriedrich authored Mar 4, 2024
1 parent fdb2bba commit 2c1a086
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down

0 comments on commit 2c1a086

Please sign in to comment.