Skip to content

Commit

Permalink
Improve rainbird device reliability by sending requests serially (#87603
Browse files Browse the repository at this point in the history
)

Send rainbird requests serially
  • Loading branch information
allenporter authored Feb 7, 2023
1 parent af59623 commit 37bb1e8
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions homeassistant/components/rainbird/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import annotations

import asyncio
from dataclasses import dataclass
import datetime
import logging
Expand Down Expand Up @@ -84,27 +83,18 @@ async def _async_update_data(self) -> RainbirdDeviceState:
raise UpdateFailed(f"Error communicating with Device: {err}") from err

async def _fetch_data(self) -> RainbirdDeviceState:
"""Fetch data from the Rain Bird device."""
(zones, states, rain, rain_delay) = await asyncio.gather(
self._fetch_zones(),
self._controller.get_zone_states(),
self._controller.get_rain_sensor_state(),
self._controller.get_rain_delay(),
)
"""Fetch data from the Rain Bird device.
Rainbird devices can only reliably handle a single request at a time,
so the requests are sent serially.
"""
available_stations = await self._controller.get_available_stations()
states = await self._controller.get_zone_states()
rain = await self._controller.get_rain_sensor_state()
rain_delay = await self._controller.get_rain_delay()
return RainbirdDeviceState(
zones=set(zones),
active_zones={zone for zone in zones if states.active(zone)},
zones=available_stations.active_set,
active_zones=states.active_set,
rain=rain,
rain_delay=rain_delay,
)

async def _fetch_zones(self) -> set[int]:
"""Fetch the zones from the device, caching the results."""
if self._zones is None:
available_stations = await self._controller.get_available_stations()
self._zones = {
zone
for zone in range(1, available_stations.stations.count + 1)
if available_stations.stations.active(zone)
}
return self._zones

0 comments on commit 37bb1e8

Please sign in to comment.