Skip to content
Merged
Show file tree
Hide file tree
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
28 changes: 9 additions & 19 deletions homeassistant/components/rainmachine/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Support for RainMachine devices."""
from __future__ import annotations

import asyncio
from collections.abc import Callable, Coroutine
from dataclasses import dataclass
from datetime import timedelta
Expand Down Expand Up @@ -206,13 +205,10 @@ async def async_update_programs_and_zones(
programs affect zones and certain combinations of zones affect programs.
"""
data: RainMachineData = hass.data[DOMAIN][entry.entry_id]

await asyncio.gather(
*[
data.coordinators[DATA_PROGRAMS].async_refresh(),
data.coordinators[DATA_ZONES].async_refresh(),
]
)
# No gather here to allow http keep-alive to reuse
# the connection for each coordinator.
await data.coordinators[DATA_PROGRAMS].async_refresh()
await data.coordinators[DATA_ZONES].async_refresh()


async def async_setup_entry( # noqa: C901
Expand Down Expand Up @@ -302,14 +298,6 @@ async def async_update(api_category: str) -> dict:

return data

async def async_init_coordinator(
coordinator: RainMachineDataUpdateCoordinator,
) -> None:
"""Initialize a RainMachineDataUpdateCoordinator."""
await coordinator.async_initialize()
await coordinator.async_config_entry_first_refresh()

controller_init_tasks = []
coordinators = {}
for api_category, update_interval in COORDINATOR_UPDATE_INTERVAL_MAP.items():
coordinator = coordinators[api_category] = RainMachineDataUpdateCoordinator(
Expand All @@ -320,9 +308,11 @@ async def async_init_coordinator(
update_interval=update_interval,
update_method=partial(async_update, api_category),
)
controller_init_tasks.append(async_init_coordinator(coordinator))

await asyncio.gather(*controller_init_tasks)
coordinator.async_initialize()
# Its generally faster not to gather here so we can
# reuse the connection instead of creating a new
# connection for each coordinator.
await coordinator.async_config_entry_first_refresh()

hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.entry_id] = RainMachineData(
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/rainmachine/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ def __init__(
self.config_entry.entry_id
)

async def async_initialize(self) -> None:
@callback
def async_initialize(self) -> None:
"""Initialize the coordinator."""

@callback
Expand Down