1
0
mirror of https://github.com/home-assistant/core.git synced 2026-05-27 02:36:00 +01:00
Files
core/homeassistant/components/freshr/__init__.py
T
Leon Grave 6fa8e71b21 Add freshr integration, based on pyfreshr (#164538)
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2026-03-09 15:26:03 +01:00

48 lines
1.3 KiB
Python

"""The Fresh-r integration."""
import asyncio
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from .coordinator import (
FreshrConfigEntry,
FreshrData,
FreshrDevicesCoordinator,
FreshrReadingsCoordinator,
)
_PLATFORMS: list[Platform] = [Platform.SENSOR]
async def async_setup_entry(hass: HomeAssistant, entry: FreshrConfigEntry) -> bool:
"""Set up Fresh-r from a config entry."""
devices_coordinator = FreshrDevicesCoordinator(hass, entry)
await devices_coordinator.async_config_entry_first_refresh()
readings: dict[str, FreshrReadingsCoordinator] = {
device.id: FreshrReadingsCoordinator(
hass, entry, device, devices_coordinator.client
)
for device in devices_coordinator.data
}
await asyncio.gather(
*(
coordinator.async_config_entry_first_refresh()
for coordinator in readings.values()
)
)
entry.runtime_data = FreshrData(
devices=devices_coordinator,
readings=readings,
)
await hass.config_entries.async_forward_entry_setups(entry, _PLATFORMS)
return True
async def async_unload_entry(hass: HomeAssistant, entry: FreshrConfigEntry) -> bool:
"""Unload a config entry."""
return await hass.config_entries.async_unload_platforms(entry, _PLATFORMS)