mirror of
https://github.com/home-assistant/core.git
synced 2026-06-02 05:34:15 +01:00
d766aae436
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: frenck <195327+frenck@users.noreply.github.com>
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
"""Refoss devices platform loader."""
|
|
|
|
from datetime import timedelta
|
|
from typing import Final
|
|
|
|
from homeassistant.const import Platform
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.event import async_track_time_interval
|
|
|
|
from .bridge import DiscoveryService, RefossConfigEntry
|
|
from .const import DISCOVERY_SCAN_INTERVAL
|
|
from .util import refoss_discovery_server
|
|
|
|
PLATFORMS: Final = [
|
|
Platform.SENSOR,
|
|
Platform.SWITCH,
|
|
]
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: RefossConfigEntry) -> bool:
|
|
"""Set up Refoss from a config entry."""
|
|
discover = await refoss_discovery_server(hass)
|
|
refoss_discovery = DiscoveryService(hass, entry, discover)
|
|
entry.runtime_data = refoss_discovery
|
|
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
|
|
|
async def _async_scan_update(_=None):
|
|
await refoss_discovery.discovery.broadcast_msg()
|
|
|
|
await _async_scan_update()
|
|
|
|
entry.async_on_unload(
|
|
async_track_time_interval(
|
|
hass, _async_scan_update, timedelta(seconds=DISCOVERY_SCAN_INTERVAL)
|
|
)
|
|
)
|
|
|
|
return True
|
|
|
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: RefossConfigEntry) -> bool:
|
|
"""Unload a config entry."""
|
|
entry.runtime_data.discovery.clean_up()
|
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|