From 213a8e2c212e0abe55098099f3114e99c2a98761 Mon Sep 17 00:00:00 2001 From: Giovanni Iachello <60585229+giachello@users.noreply.github.com> Date: Thu, 26 May 2022 11:44:42 -0700 Subject: [PATCH] fix: improve handling on 0 Watts spurious power reads (#317) closes #287 --- teslajsonpy/homeassistant/power.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/teslajsonpy/homeassistant/power.py b/teslajsonpy/homeassistant/power.py index 80ab3324..c89558c5 100644 --- a/teslajsonpy/homeassistant/power.py +++ b/teslajsonpy/homeassistant/power.py @@ -134,9 +134,15 @@ def refresh(self) -> None: """ super().refresh() data = self._controller.get_power_params(self._id) + if data: # Note: Some systems that pre-date Tesla aquisition of SolarCity will have `grid_status: Unknown`, - # but will have solar power values + # but will have solar power values. At the same time, newer systems will report spurious reads of 0 Watts + # and grid status unknown. If solar power is 0 return null. + if "grid_status" in data and data["grid_status"] == "Unknown" and data["solar_power"] == 0: + _LOGGER.debug("Spurious energy site power read") + return + self.__power = data["solar_power"] if data["solar_power"] is not None: self.__generating_status = (