Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The songpal component."""
2 
3 import voluptuous as vol
4 
5 from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
6 from homeassistant.const import CONF_NAME, Platform
7 from homeassistant.core import HomeAssistant
8 from homeassistant.helpers import config_validation as cv
9 from homeassistant.helpers.typing import ConfigType
10 
11 from .const import CONF_ENDPOINT, DOMAIN
12 
13 SONGPAL_CONFIG_SCHEMA = vol.Schema(
14  {vol.Optional(CONF_NAME): cv.string, vol.Required(CONF_ENDPOINT): cv.string}
15 )
16 
17 CONFIG_SCHEMA = vol.Schema(
18  {vol.Optional(DOMAIN): vol.All(cv.ensure_list, [SONGPAL_CONFIG_SCHEMA])},
19  extra=vol.ALLOW_EXTRA,
20 )
21 
22 PLATFORMS = [Platform.MEDIA_PLAYER]
23 
24 
25 async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
26  """Set up songpal environment."""
27  if (conf := config.get(DOMAIN)) is None:
28  return True
29  for config_entry in conf:
30  hass.async_create_task(
31  hass.config_entries.flow.async_init(
32  DOMAIN,
33  context={"source": SOURCE_IMPORT},
34  data=config_entry,
35  ),
36  )
37  return True
38 
39 
40 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
41  """Set up songpal media player."""
42  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
43  return True
44 
45 
46 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
47  """Unload songpal media player."""
48  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:46
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:40
bool async_setup(HomeAssistant hass, ConfigType config)
Definition: __init__.py:25