1 """The Aprilaire integration."""
3 from __future__
import annotations
7 from pyaprilaire.const
import Attribute
14 from .coordinator
import AprilaireConfigEntry, AprilaireCoordinator
16 PLATFORMS: list[Platform] = [
23 _LOGGER = logging.getLogger(__name__)
27 """Set up a config entry for Aprilaire."""
29 host = entry.data[CONF_HOST]
30 port = entry.data[CONF_PORT]
33 await coordinator.start_listen()
35 async
def ready_callback(ready: bool) ->
None:
37 mac_address =
format_mac(coordinator.data[Attribute.MAC_ADDRESS])
39 if mac_address != entry.unique_id:
42 entry.runtime_data = coordinator
43 entry.async_on_unload(coordinator.stop_listen)
45 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
47 async
def _async_close(_: Event) ->
None:
48 coordinator.stop_listen()
50 entry.async_on_unload(
51 hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _async_close)
54 _LOGGER.error(
"Failed to wait for ready")
56 coordinator.stop_listen()
58 raise ConfigEntryNotReady
60 await coordinator.wait_for_ready(ready_callback)
66 """Unload a config entry."""
67 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_unload_entry(HomeAssistant hass, AprilaireConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, AprilaireConfigEntry entry)