From b941d6cb3ba89eb63c4776884fb9062c6122174d Mon Sep 17 00:00:00 2001 From: David Radcliffe Date: Sat, 5 Oct 2024 19:05:28 -0400 Subject: [PATCH] handle missing advice --- custom_components/waterguru/sensor.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/custom_components/waterguru/sensor.py b/custom_components/waterguru/sensor.py index e4e3526..7fa1972 100644 --- a/custom_components/waterguru/sensor.py +++ b/custom_components/waterguru/sensor.py @@ -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