1
0
mirror of https://github.com/home-assistant/core.git synced 2026-07-07 23:06:34 +01:00
Files
core/homeassistant/components/izone/config_flow.py
T
2026-06-01 08:40:55 +02:00

43 lines
1.2 KiB
Python

"""Config flow for izone."""
import asyncio
from contextlib import suppress
import logging
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import config_entry_flow
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from .const import DISPATCH_CONTROLLER_DISCOVERED, DOMAIN, TIMEOUT_DISCOVERY
from .discovery import async_start_discovery_service, async_stop_discovery_service
_LOGGER = logging.getLogger(__name__)
async def _async_has_devices(hass: HomeAssistant) -> bool:
controller_ready = asyncio.Event()
@callback
def dispatch_discovered(_):
controller_ready.set()
async_dispatcher_connect(hass, DISPATCH_CONTROLLER_DISCOVERED, dispatch_discovered)
disco = await async_start_discovery_service(hass)
with suppress(TimeoutError):
async with asyncio.timeout(TIMEOUT_DISCOVERY):
await controller_ready.wait()
controllers = await disco.pi_disco.fetch_controllers()
if not controllers:
await async_stop_discovery_service(hass)
_LOGGER.debug("No controllers found")
return False
_LOGGER.debug("Controllers %s", controllers)
return True
config_entry_flow.register_discovery_flow(DOMAIN, "iZone Aircon", _async_has_devices)