From 1ad468aefe1e778365bff31a444720762585ba79 Mon Sep 17 00:00:00 2001 From: Felipe Martins Diel <41558831+felipediel@users.noreply.github.com> Date: Sat, 7 Nov 2020 05:02:53 -0300 Subject: [PATCH] Clean up get_energy() (#471) Amend: Fix sp3s energy monitoring (#504) --- broadlink/switch.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/broadlink/switch.py b/broadlink/switch.py index 9622545..fe693ab 100644 --- a/broadlink/switch.py +++ b/broadlink/switch.py @@ -212,16 +212,14 @@ class sp2(device): payload = self.decrypt(response[0x38:]) return bool(payload[0x4] == 2 or payload[0x4] == 3 or payload[0x4] == 0xFF) - def get_energy(self) -> int: - """Return the energy state of the device.""" + def get_energy(self) -> float: + """Return the power consumption in W.""" packet = bytearray([8, 0, 254, 1, 5, 1, 0, 0, 0, 45]) response = self.send_packet(0x6A, packet) check_error(response[0x22:0x24]) payload = self.decrypt(response[0x38:]) - return ( - int(hex(payload[0x07] * 256 + payload[0x06])[2:]) - + int(hex(payload[0x05])[2:]) / 100.0 - ) + energy = payload[0x7:0x4:-1].hex() + return int(energy) / 100 class sp4(device):