mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Improve rainbird device reliability by sending requests serially (#87603)
Send rainbird requests serially
This commit is contained in:
parent
a2c9f92420
commit
2e541e7ef6
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
@ -84,27 +83,18 @@ class RainbirdUpdateCoordinator(DataUpdateCoordinator[RainbirdDeviceState]):
|
|||||||
raise UpdateFailed(f"Error communicating with Device: {err}") from err
|
raise UpdateFailed(f"Error communicating with Device: {err}") from err
|
||||||
|
|
||||||
async def _fetch_data(self) -> RainbirdDeviceState:
|
async def _fetch_data(self) -> RainbirdDeviceState:
|
||||||
"""Fetch data from the Rain Bird device."""
|
"""Fetch data from the Rain Bird device.
|
||||||
(zones, states, rain, rain_delay) = await asyncio.gather(
|
|
||||||
self._fetch_zones(),
|
Rainbird devices can only reliably handle a single request at a time,
|
||||||
self._controller.get_zone_states(),
|
so the requests are sent serially.
|
||||||
self._controller.get_rain_sensor_state(),
|
"""
|
||||||
self._controller.get_rain_delay(),
|
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(
|
return RainbirdDeviceState(
|
||||||
zones=set(zones),
|
zones=available_stations.active_set,
|
||||||
active_zones={zone for zone in zones if states.active(zone)},
|
active_zones=states.active_set,
|
||||||
rain=rain,
|
rain=rain,
|
||||||
rain_delay=rain_delay,
|
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
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user