Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Dune HD component."""
2 
3 from __future__ import annotations
4 
5 from typing import Final
6 
7 from pdunehd import DuneHDPlayer
8 
9 from homeassistant.config_entries import ConfigEntry
10 from homeassistant.const import CONF_HOST, Platform
11 from homeassistant.core import HomeAssistant
12 
13 from .const import DOMAIN
14 
15 PLATFORMS: Final[list[Platform]] = [Platform.MEDIA_PLAYER]
16 
17 
18 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
19  """Set up a config entry."""
20  host: str = entry.data[CONF_HOST]
21 
22  player = DuneHDPlayer(host)
23 
24  hass.data.setdefault(DOMAIN, {})
25  hass.data[DOMAIN][entry.entry_id] = player
26 
27  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
28 
29  return True
30 
31 
32 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
33  """Unload a config entry."""
34  unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
35  if unload_ok:
36  hass.data[DOMAIN].pop(entry.entry_id)
37 
38  return unload_ok
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:32
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:18