Home Assistant Unofficial Reference 2024.12.1
config_flow.py
Go to the documentation of this file.
1 """Config flow for izone."""
2 
3 import asyncio
4 from contextlib import suppress
5 import logging
6 
7 from homeassistant.core import HomeAssistant, callback
8 from homeassistant.helpers import config_entry_flow
9 from homeassistant.helpers.dispatcher import async_dispatcher_connect
10 
11 from .const import DISPATCH_CONTROLLER_DISCOVERED, IZONE, TIMEOUT_DISCOVERY
12 from .discovery import async_start_discovery_service, async_stop_discovery_service
13 
14 _LOGGER = logging.getLogger(__name__)
15 
16 
17 async def _async_has_devices(hass: HomeAssistant) -> bool:
18  controller_ready = asyncio.Event()
19 
20  @callback
21  def dispatch_discovered(_):
22  controller_ready.set()
23 
24  async_dispatcher_connect(hass, DISPATCH_CONTROLLER_DISCOVERED, dispatch_discovered)
25 
26  disco = await async_start_discovery_service(hass)
27 
28  with suppress(TimeoutError):
29  async with asyncio.timeout(TIMEOUT_DISCOVERY):
30  await controller_ready.wait()
31 
32  if not disco.pi_disco.controllers:
34  _LOGGER.debug("No controllers found")
35  return False
36 
37  _LOGGER.debug("Controllers %s", disco.pi_disco.controllers)
38  return True
39 
40 
41 config_entry_flow.register_discovery_flow(IZONE, "iZone Aircon", _async_has_devices)
None async_stop_discovery_service(HomeAssistant hass)
Definition: discovery.py:69
AbstractDiscoveryService async_start_discovery_service(HomeAssistant hass)
Definition: discovery.py:52
bool _async_has_devices(HomeAssistant hass)
Definition: config_flow.py:17
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)
Definition: dispatcher.py:103