From 0306e05fb9e035138a72bdc2cb0847077d857646 Mon Sep 17 00:00:00 2001 From: Steven B <51370195+sdb9696@users.noreply.github.com> Date: Wed, 28 Feb 2024 17:57:02 +0000 Subject: [PATCH] Fix energy module calling get_current_power (#798) --- kasa/smart/modules/energymodule.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/kasa/smart/modules/energymodule.py b/kasa/smart/modules/energymodule.py index 5782a23f..0479de29 100644 --- a/kasa/smart/modules/energymodule.py +++ b/kasa/smart/modules/energymodule.py @@ -43,12 +43,12 @@ class EnergyModule(SmartModule): def query(self) -> Dict: """Query to execute during the update cycle.""" - return { + req = { "get_energy_usage": None, - # The current_power in get_energy_usage is more precise (mw vs. w), - # making this rather useless, but maybe there are version differences? - "get_current_power": None, } + if self.supported_version > 1: + req["get_current_power"] = None + return req @property def current_power(self): @@ -58,7 +58,9 @@ class EnergyModule(SmartModule): @property def energy(self): """Return get_energy_usage results.""" - return self.data["get_energy_usage"] + if en := self.data.get("get_energy_usage"): + return en + return self.data @property def emeter_realtime(self):