From af69628e99b2d8d53e0d8070b0e20f18a283f451 Mon Sep 17 00:00:00 2001 From: Matt Zimmerman Date: Mon, 3 Nov 2025 20:06:19 -0800 Subject: [PATCH] Fix AttributeError and TypeError in light and pump state checks - Fix _wait_for_state_change to use get_status_method consistently from the start - Add safety checks in SpaStateFull for None values in lights and pumps - Resolves TypeError when iterating over None lights - Resolves AttributeError when accessing pumps on SpaState --- smarttub/api.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/smarttub/api.py b/smarttub/api.py index aa639b9..09b10ea 100644 --- a/smarttub/api.py +++ b/smarttub/api.py @@ -196,8 +196,10 @@ async def _wait_for_state_change( RuntimeError if the state change is not reflected within the timeout period """ start_time = datetime.datetime.now().timestamp() + # Use the provided method if available, otherwise use default get_status + status_method = get_status_method if get_status_method else self.get_status while True: - state = await self.get_status() + state = await status_method() if check_func(state): return state @@ -206,9 +208,6 @@ async def _wait_for_state_change( await asyncio.sleep(0.5) - if get_status_method: - state = await get_status_method() - async def get_status(self) -> "SpaState": """Query the status of the spa.""" return SpaState(self, **await self.request("GET", "status")) @@ -407,10 +406,12 @@ class SpaStateFull(SpaState): def __init__(self, spa: Spa, state: dict): super().__init__(spa, **state) self.lights = [ - SpaLight(spa, **light_props) for light_props in self.properties["lights"] + SpaLight(spa, **light_props) + for light_props in (self.properties.get("lights") or []) ] self.pumps = [ - SpaPump(spa, **pump_props) for pump_props in self.properties["pumps"] + SpaPump(spa, **pump_props) + for pump_props in (self.properties.get("pumps") or []) ] self.sensors = [ SpaSensor(spa, **sensor_props)