Reduce the amount of data fetched in individual Hydrawise API calls (#120328)

This commit is contained in:
David Knowles 2024-06-24 14:58:54 -04:00 committed by GitHub
parent 46dcf1dc44
commit 3b79ab6e18
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 11 additions and 10 deletions

View file

@ -40,13 +40,17 @@ class HydrawiseDataUpdateCoordinator(DataUpdateCoordinator[HydrawiseData]):
async def _async_update_data(self) -> HydrawiseData:
"""Fetch the latest data from Hydrawise."""
user = await self.api.get_user()
# Don't fetch zones. We'll fetch them for each controller later.
# This is to prevent 502 errors in some cases.
# See: https://github.com/home-assistant/core/issues/120128
user = await self.api.get_user(fetch_zones=False)
controllers = {}
zones = {}
sensors = {}
daily_water_use: dict[int, ControllerWaterUseSummary] = {}
for controller in user.controllers:
controllers[controller.id] = controller
controller.zones = await self.api.get_zones(controller)
for zone in controller.zones:
zones[zone.id] = zone
for sensor in controller.sensors: