From c41351bce63331871fd13a36a67eea300c2ba4af Mon Sep 17 00:00:00 2001 From: jonnynch Date: Fri, 12 Jul 2024 02:33:54 +1000 Subject: [PATCH] fix: check empty energy_info to avoid error (#780) I have two P110, and the first one was not working after I added the second one. Based on the log, the energy_info is None when startup, so, the following entities are all failed to load. And from the Tapo app, the energy info is shown as "--" in the first P110 as well. After I have added the Null check, there is no startup error and the first P110 is now working (at least can be turned on/off via HA) Although the energy_info is still empty in HA, it is the same result as Tapo app. --- custom_components/tapo/sensors/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/tapo/sensors/__init__.py b/custom_components/tapo/sensors/__init__.py index bd360b5..a92a19f 100644 --- a/custom_components/tapo/sensors/__init__.py +++ b/custom_components/tapo/sensors/__init__.py @@ -23,7 +23,7 @@ def get_config(self) -> SensorConfig: def get_value(self, coordinator: TapoDataCoordinator) -> StateType: if energy := coordinator.device.get_component(EnergyComponent): - return energy.energy_info.today_energy / 1000 + return energy.energy_info.today_energy / 1000 if energy.energy_info else None return None @@ -38,7 +38,7 @@ def get_config(self) -> SensorConfig: def get_value(self, coordinator: TapoDataCoordinator) -> StateType: if energy := coordinator.device.get_component(EnergyComponent): - return energy.energy_info.month_energy / 1000 + return energy.energy_info.month_energy / 1000 if energy.energy_info else None return None