Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """ROMY Integration."""
2 
3 import romy
4 
5 from homeassistant.config_entries import ConfigEntry
6 from homeassistant.const import CONF_HOST, CONF_PASSWORD
7 from homeassistant.core import HomeAssistant
8 
9 from .const import DOMAIN, LOGGER, PLATFORMS
10 from .coordinator import RomyVacuumCoordinator
11 
12 
13 async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
14  """Initialize the ROMY platform via config entry."""
15 
16  new_romy = await romy.create_romy(
17  config_entry.data[CONF_HOST], config_entry.data.get(CONF_PASSWORD, "")
18  )
19 
20  coordinator = RomyVacuumCoordinator(hass, new_romy)
21  await coordinator.async_config_entry_first_refresh()
22 
23  hass.data.setdefault(DOMAIN, {})[config_entry.entry_id] = coordinator
24 
25  await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
26 
27  config_entry.async_on_unload(config_entry.add_update_listener(update_listener))
28 
29  return True
30 
31 
32 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
33  """Handle removal of an entry."""
34  if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
35  hass.data[DOMAIN].pop(entry.entry_id)
36  return unload_ok
37 
38 
39 async def update_listener(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
40  """Handle options update."""
41  LOGGER.debug("update_listener")
42  await hass.config_entries.async_reload(config_entry.entry_id)
None update_listener(HomeAssistant hass, ConfigEntry config_entry)
Definition: __init__.py:39
bool async_setup_entry(HomeAssistant hass, ConfigEntry config_entry)
Definition: __init__.py:13
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:32