Skip to content

Commit

Permalink
fix: check empty energy_info to avoid error (#780)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jonnynch authored Jul 11, 2024
1 parent 6591bfc commit c41351b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions custom_components/tapo/sensors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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


Expand Down

0 comments on commit c41351b

Please sign in to comment.