Skip to content

Commit f469c3d

Browse files
authored
Fix AttributeError and TypeError in light and pump state checks (#64)
- 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
1 parent 3f59020 commit f469c3d

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

smarttub/api.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,10 @@ async def _wait_for_state_change(
196196
RuntimeError if the state change is not reflected within the timeout period
197197
"""
198198
start_time = datetime.datetime.now().timestamp()
199+
# Use the provided method if available, otherwise use default get_status
200+
status_method = get_status_method if get_status_method else self.get_status
199201
while True:
200-
state = await self.get_status()
202+
state = await status_method()
201203
if check_func(state):
202204
return state
203205

@@ -206,9 +208,6 @@ async def _wait_for_state_change(
206208

207209
await asyncio.sleep(0.5)
208210

209-
if get_status_method:
210-
state = await get_status_method()
211-
212211
async def get_status(self) -> "SpaState":
213212
"""Query the status of the spa."""
214213
return SpaState(self, **await self.request("GET", "status"))
@@ -407,10 +406,12 @@ class SpaStateFull(SpaState):
407406
def __init__(self, spa: Spa, state: dict):
408407
super().__init__(spa, **state)
409408
self.lights = [
410-
SpaLight(spa, **light_props) for light_props in self.properties["lights"]
409+
SpaLight(spa, **light_props)
410+
for light_props in (self.properties.get("lights") or [])
411411
]
412412
self.pumps = [
413-
SpaPump(spa, **pump_props) for pump_props in self.properties["pumps"]
413+
SpaPump(spa, **pump_props)
414+
for pump_props in (self.properties.get("pumps") or [])
414415
]
415416
self.sensors = [
416417
SpaSensor(spa, **sensor_props)

0 commit comments

Comments
 (0)