Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The DLNA Digital Media Server integration.
2 
3 A single config entry is used, with SSDP discovery for media servers. Each
4 server is wrapped in a DmsEntity, and the server's USN is used as the unique_id.
5 """
6 
7 from __future__ import annotations
8 
9 from homeassistant.config_entries import ConfigEntry
10 from homeassistant.core import HomeAssistant
11 
12 from .const import CONF_SOURCE_ID, LOGGER
13 from .dms import get_domain_data
14 from .util import generate_source_id
15 
16 
17 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
18  """Set up DLNA DMS device from a config entry."""
19  LOGGER.debug("Setting up config entry: %s", entry.unique_id)
20 
21  # Soft-migrate entry if it's missing data keys
22  if CONF_SOURCE_ID not in entry.data:
23  LOGGER.debug("Adding CONF_SOURCE_ID to entry %s", entry.data)
24  data = dict(entry.data)
25  data[CONF_SOURCE_ID] = generate_source_id(hass, entry.title)
26  hass.config_entries.async_update_entry(entry, data=data)
27 
28  # Forward setup to this domain's data manager
29  return await get_domain_data(hass).async_setup_entry(entry)
30 
31 
32 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
33  """Unload a config entry."""
34  LOGGER.debug("Unloading config entry: %s", entry.unique_id)
35 
36  # Forward unload to this domain's data manager
37  return await get_domain_data(hass).async_unload_entry(entry)
DlnaDmrData get_domain_data(HomeAssistant hass)
Definition: data.py:120
str generate_source_id(HomeAssistant hass, str name)
Definition: util.py:11
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:17
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:32