[nikohomecontrol] Fix energy meter. (#10546)

Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
This commit is contained in:
Mark Herwege 2021-04-22 20:34:12 +02:00 committed by GitHub
parent 0e4810e651
commit 061ecda321
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -577,7 +577,9 @@ public class NikoHomeControlCommunication2 extends NikoHomeControlCommunication
deviceProperties.stream().map(p -> p.electricalPower).filter(Objects::nonNull).findFirst()
.ifPresent(electricalPower -> {
try {
energyMeter.setPower(Integer.parseInt(electricalPower));
// Sometimes API sends a fractional part, although API should only send whole units in W,
// therefore drop fractional part
energyMeter.setPower((int) Double.parseDouble(electricalPower));
logger.trace("setting energy meter {} power to {}", energyMeter.getId(), electricalPower);
} catch (NumberFormatException e) {
energyMeter.setPower(null);