Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Volumio integration."""
2 
3 from pyvolumio import CannotConnectError, Volumio
4 
5 from homeassistant.config_entries import ConfigEntry
6 from homeassistant.const import CONF_HOST, CONF_PORT, Platform
7 from homeassistant.core import HomeAssistant
8 from homeassistant.exceptions import ConfigEntryNotReady
9 from homeassistant.helpers.aiohttp_client import async_get_clientsession
10 
11 from .const import DATA_INFO, DATA_VOLUMIO, DOMAIN
12 
13 PLATFORMS = [Platform.MEDIA_PLAYER]
14 
15 
16 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
17  """Set up Volumio from a config entry."""
18 
19  volumio = Volumio(
20  entry.data[CONF_HOST], entry.data[CONF_PORT], async_get_clientsession(hass)
21  )
22  try:
23  info = await volumio.get_system_version()
24  except CannotConnectError as error:
25  raise ConfigEntryNotReady from error
26 
27  hass.data.setdefault(DOMAIN, {})[entry.entry_id] = {
28  DATA_VOLUMIO: volumio,
29  DATA_INFO: info,
30  }
31 
32  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
33 
34  return True
35 
36 
37 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
38  """Unload a config entry."""
39  unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
40  if unload_ok:
41  hass.data[DOMAIN].pop(entry.entry_id)
42 
43  return unload_ok
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:37
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:16
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)