mirror of
https://github.com/home-assistant/core.git
synced 2026-09-25 08:51:46 -04:00
Add coroutines to MELCloud Home's coordinator (#181110)
This commit is contained in:
@@ -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,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user