Skip to content

Commit

Permalink
handle missing advice
Browse files Browse the repository at this point in the history
  • Loading branch information
dwradcliffe committed Oct 5, 2024
1 parent 32424b4 commit b941d6c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions custom_components/waterguru/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,11 @@ def extra_state_attributes(self) -> dict[str, str] | None:
WaterGuruEntityAttributes.STATUS_COLOR: m.get("status"),
}

if m.get("alerts") is not None and len(m.get("alerts")) > 0 and m.get("alerts")[0].get("advice") is not None:
a[WaterGuruEntityAttributes.ADVICE] = m.get("alerts")[0].get("advice").get("action").get("summary")
alerts = m.get("alerts")
if alerts:
advice = alerts[0].get("advice", {}).get("action", {}).get("summary")
if advice is not None:
a[WaterGuruEntityAttributes.ADVICE] = advice

return a

Expand Down

0 comments on commit b941d6c

Please sign in to comment.