Home Assistant Unofficial Reference 2024.12.1
config_flow.py
Go to the documentation of this file.
1 """Config flow for Gree."""
2 
3 from greeclimate.discovery import Discovery
4 
5 from homeassistant.components.network import async_get_ipv4_broadcast_addresses
6 from homeassistant.core import HomeAssistant
7 from homeassistant.helpers import config_entry_flow
8 
9 from .const import DISCOVERY_TIMEOUT, DOMAIN
10 
11 
12 async def _async_has_devices(hass: HomeAssistant) -> bool:
13  """Return if there are devices that can be discovered."""
14  gree_discovery = Discovery(DISCOVERY_TIMEOUT)
15  bcast_addr = list(await async_get_ipv4_broadcast_addresses(hass))
16  devices = await gree_discovery.scan(
17  wait_for=DISCOVERY_TIMEOUT, bcast_ifaces=bcast_addr
18  )
19  return len(devices) > 0
20 
21 
22 config_entry_flow.register_discovery_flow(DOMAIN, "Gree Climate", _async_has_devices)
bool _async_has_devices(HomeAssistant hass)
Definition: config_flow.py:12
set[IPv4Address] async_get_ipv4_broadcast_addresses(HomeAssistant hass)
Definition: __init__.py:104