1 """The Big Ass Fans integration."""
3 from __future__
import annotations
5 from asyncio
import timeout
7 from aiobafi6
import Device, Service
8 from aiobafi6.discovery
import PORT
9 from aiobafi6.exceptions
import DeviceUUIDMismatchError
16 from .const
import QUERY_INTERVAL, RUN_TIMEOUT
18 type BAFConfigEntry = ConfigEntry[Device]
21 PLATFORMS: list[Platform] = [
22 Platform.BINARY_SENSOR,
33 """Set up Big Ass Fans from a config entry."""
34 ip_address = entry.data[CONF_IP_ADDRESS]
36 service = Service(ip_addresses=[ip_address], uuid=entry.unique_id, port=PORT)
37 device =
Device(service, query_interval_seconds=QUERY_INTERVAL)
38 run_future = device.async_run()
41 async
with timeout(RUN_TIMEOUT):
42 await device.async_wait_available()
43 except DeviceUUIDMismatchError
as ex:
45 f
"Unexpected device found at {ip_address}; expected {entry.unique_id}, found {device.dns_sd_uuid}"
47 except TimeoutError
as ex:
52 def _async_cancel_run() -> None:
55 entry.runtime_data = device
56 entry.async_on_unload(_async_cancel_run)
57 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
63 """Unload a config entry."""
64 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_unload_entry(HomeAssistant hass, BAFConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, BAFConfigEntry entry)