Skip to content

Commit

Permalink
[plugwise] Fix 'power' channel not correctly updated with power produ…
Browse files Browse the repository at this point in the history
…ction (openhab#11746)

This fixes the issue that the 'power' channel would not update with the correct state because the number of pulses in the PowerInformationResponseMessage is signed instead of unsigned.
When the binding detected these strange readings it would normally log: "Circle (...) is in a kind of error state ...".

Signed-off-by: Wouter Born <github@maindrain.net>
Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com>
  • Loading branch information
wborn authored and andrasU committed Nov 12, 2022
1 parent c601bf8 commit 2bf997e
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class PowerInformationResponseMessage extends Message {

private static final Pattern PAYLOAD_PATTERN = Pattern.compile("(\\w{16})(\\w{4})(\\w{4})(\\w{8})(\\w{8})(\\w{4})");
private static final double NANOSECONDS_CORRECTION_DIVISOR = 0.000046875; // 46875 divided by nanos per second
private static final Duration ONE_HOUR = Duration.ofHours(1);

private Energy oneSecond;
private Energy eightSecond;
Expand Down Expand Up @@ -67,12 +68,12 @@ protected void parsePayload() {
ZonedDateTime utcNow = ZonedDateTime.now(UTC);
macAddress = new MACAddress(matcher.group(1));
nanosCorrection = Math.round(Integer.parseInt(matcher.group(6), 16) / NANOSECONDS_CORRECTION_DIVISOR);
oneSecond = new Energy(utcNow, Integer.parseInt(matcher.group(2), 16),
oneSecond = new Energy(utcNow, (short) Integer.parseInt(matcher.group(2), 16),
Duration.ofSeconds(1, nanosCorrection));
eightSecond = new Energy(utcNow, Integer.parseInt(matcher.group(3), 16),
eightSecond = new Energy(utcNow, (short) Integer.parseInt(matcher.group(3), 16),
Duration.ofSeconds(8, nanosCorrection));
oneHourConsumed = new Energy(utcNow, Long.parseLong(matcher.group(4), 16), Duration.ofHours(1));
oneHourProduced = new Energy(utcNow, Long.parseLong(matcher.group(5), 16), Duration.ofHours(1));
oneHourConsumed = new Energy(utcNow, Long.parseLong(matcher.group(4), 16), ONE_HOUR);
oneHourProduced = new Energy(utcNow, Long.parseLong(matcher.group(5), 16), ONE_HOUR);
} else {
throw new PlugwisePayloadMismatchException(POWER_INFORMATION_RESPONSE, PAYLOAD_PATTERN, payload);
}
Expand Down

0 comments on commit 2bf997e

Please sign in to comment.