Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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