Skip to content

Commit

Permalink
powermeter: catch invalid values for power and energy
Browse files Browse the repository at this point in the history
There are devices that can return empty values for these fields. To
avoid crashing (throwing uncatched exception) we catch these.

Fixes: issue #109

Signed-off-by: Heiko Thiery <[email protected]>
  • Loading branch information
hthiery committed Jan 19, 2025
1 parent c2d065e commit 2388c5c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pyfritzhome/devicetypes/fritzhomedevicepowermeter.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,17 @@ def has_powermeter(self):
def _update_powermeter_from_node(self, node):
_LOGGER.debug("update powermeter device")
val = node.find("powermeter")
self.power = int(val.findtext("power"))
self.energy = int(val.findtext("energy"))

try:
self.power = int(val.findtext("power"))
except Exception:
pass

try:
self.energy = int(val.findtext("energy"))
except Exception:
pass

try:
self.voltage = int(val.findtext("voltage"))
except Exception:
Expand Down

0 comments on commit 2388c5c

Please sign in to comment.