From 10eb0bb61c5e1c20e13f263e107fd88d6a7a783a Mon Sep 17 00:00:00 2001 From: Erwin Douna Date: Thu, 3 Sep 2026 08:18:15 +0200 Subject: [PATCH] Add coroutines to MELCloud Home's coordinator (#181110) --- .../components/melcloud_home/coordinator.py | 17 ++++++++++++----- tests/components/melcloud_home/test_init.py | 4 ++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/melcloud_home/coordinator.py b/homeassistant/components/melcloud_home/coordinator.py index 671463a2c6b7..a415327eb8c8 100644 --- a/homeassistant/components/melcloud_home/coordinator.py +++ b/homeassistant/components/melcloud_home/coordinator.py @@ -1,6 +1,7 @@ """Coordinator for MELCloud Home.""" -from collections.abc import Callable +import asyncio +from collections.abc import Callable, Coroutine from dataclasses import dataclass from datetime import datetime, timedelta import logging @@ -213,14 +214,14 @@ class MelCloudHomeEnergyCoordinator(DataUpdateCoordinator[dict[str, float | None ) now = utcnow() - energy: dict[str, float | None] = {} + energy_coroutines: dict[str, Coroutine[None, None, float | None]] = {} for building in data.buildings: for ata_unit in building.air_to_air_units: if ( ata_unit.capabilities and ata_unit.capabilities.has_energy_consumed_meter ): - energy[ata_unit.id] = await self._async_get_energy( + energy_coroutines[ata_unit.id] = self._async_get_energy( ata_unit.id, start_of_month, now ) for atw_unit in building.air_to_water_units: @@ -228,8 +229,14 @@ class MelCloudHomeEnergyCoordinator(DataUpdateCoordinator[dict[str, float | None atw_unit.capabilities and atw_unit.capabilities.has_energy_consumed_meter ): - energy[atw_unit.id] = await self._async_get_energy( + energy_coroutines[atw_unit.id] = self._async_get_energy( atw_unit.id, start_of_month, now ) - return energy + return dict( + zip( + energy_coroutines, + await asyncio.gather(*energy_coroutines.values()), + strict=True, + ) + ) diff --git a/tests/components/melcloud_home/test_init.py b/tests/components/melcloud_home/test_init.py index b07541dc3905..5049dae794e0 100644 --- a/tests/components/melcloud_home/test_init.py +++ b/tests/components/melcloud_home/test_init.py @@ -224,7 +224,7 @@ async def test_energy_update_cycle_fails( mock_melcloud_client.get_energy_telemetry.side_effect = exception freezer.tick(ENERGY_UPDATE_INTERVAL) async_fire_time_changed(hass) - await hass.async_block_till_done() + await hass.async_block_till_done(wait_background_tasks=True) assert energy_coordinator.data["ata-unit-uuid-1"] is None assert energy_coordinator.data["atw-unit-uuid-1"] is None @@ -233,7 +233,7 @@ async def test_energy_update_cycle_fails( mock_melcloud_client.get_energy_telemetry.side_effect = None freezer.tick(ENERGY_UPDATE_INTERVAL) async_fire_time_changed(hass) - await hass.async_block_till_done() + await hass.async_block_till_done(wait_background_tasks=True) assert energy_coordinator.data["ata-unit-uuid-1"] is not None assert energy_coordinator.data["atw-unit-uuid-1"] is not None