Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The forked_daapd component."""
2 
3 from homeassistant.config_entries import ConfigEntry
4 from homeassistant.const import Platform
5 from homeassistant.core import HomeAssistant
6 
7 from .const import DOMAIN, HASS_DATA_REMOVE_LISTENERS_KEY, HASS_DATA_UPDATER_KEY
8 
9 PLATFORMS = [Platform.MEDIA_PLAYER]
10 
11 
12 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
13  """Set up forked-daapd from a config entry by forwarding to platform."""
14  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
15  return True
16 
17 
18 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
19  """Remove forked-daapd component."""
20  status = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
21  if status and hass.data.get(DOMAIN) and hass.data[DOMAIN].get(entry.entry_id):
22  if websocket_handler := hass.data[DOMAIN][entry.entry_id][
23  HASS_DATA_UPDATER_KEY
24  ].websocket_handler:
25  websocket_handler.cancel()
26  for remove_listener in hass.data[DOMAIN][entry.entry_id][
27  HASS_DATA_REMOVE_LISTENERS_KEY
28  ]:
29  remove_listener()
30  del hass.data[DOMAIN][entry.entry_id]
31  if not hass.data[DOMAIN]:
32  del hass.data[DOMAIN]
33  return status
web.Response get(self, web.Request request, str config_key)
Definition: view.py:88
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:18
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:12