Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Nice G.O. integration."""
2 
3 from __future__ import annotations
4 
5 import logging
6 
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.const import EVENT_HOMEASSISTANT_STOP, Platform
9 from homeassistant.core import HomeAssistant
10 
11 from .coordinator import NiceGOUpdateCoordinator
12 
13 _LOGGER = logging.getLogger(__name__)
14 PLATFORMS: list[Platform] = [
15  Platform.COVER,
16  Platform.EVENT,
17  Platform.LIGHT,
18  Platform.SWITCH,
19 ]
20 
21 type NiceGOConfigEntry = ConfigEntry[NiceGOUpdateCoordinator]
22 
23 
24 async def async_setup_entry(hass: HomeAssistant, entry: NiceGOConfigEntry) -> bool:
25  """Set up Nice G.O. from a config entry."""
26 
27  coordinator = NiceGOUpdateCoordinator(hass)
28  entry.async_on_unload(
29  hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, coordinator.async_ha_stop)
30  )
31 
32  await coordinator.async_config_entry_first_refresh()
33 
34  entry.runtime_data = coordinator
35 
36  entry.async_create_background_task(
37  hass,
38  coordinator.client_listen(),
39  "nice_go_websocket_task",
40  )
41 
42  entry.async_on_unload(coordinator.unsubscribe)
43 
44  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
45 
46  return True
47 
48 
49 async def async_unload_entry(hass: HomeAssistant, entry: NiceGOConfigEntry) -> bool:
50  """Unload a config entry."""
51  if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
52  await entry.runtime_data.api.close()
53 
54  return unload_ok
bool async_unload_entry(HomeAssistant hass, NiceGOConfigEntry entry)
Definition: __init__.py:49
bool async_setup_entry(HomeAssistant hass, NiceGOConfigEntry entry)
Definition: __init__.py:24