Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[plugwise] Fix 'power' channel not correctly updated with power production #11746

Merged
merged 1 commit into from
Dec 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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