1 """The MusicCast integration."""
3 from __future__
import annotations
7 from aiomusiccast.musiccast_device
import MusicCastDevice
15 from .const
import CONF_SERIAL, CONF_UPNP_DESC, DOMAIN
16 from .coordinator
import MusicCastDataUpdateCoordinator
18 PLATFORMS = [Platform.MEDIA_PLAYER, Platform.NUMBER, Platform.SELECT, Platform.SWITCH]
20 _LOGGER = logging.getLogger(__name__)
24 """Get the upnp description URL for a given host, using the SSPD scanner."""
25 ssdp_entries = await ssdp.async_get_discovery_info_by_st(hass,
"upnp:rootdevice")
26 matches = [w
for w
in ssdp_entries
if w.ssdp_headers.get(
"_host",
"") == host]
29 if upnp_desc := match.ssdp_location:
34 "The upnp_description was not found automatically, setting a default one"
36 upnp_desc = f
"http://{host}:49154/MediaRenderer/desc.xml"
41 """Set up MusicCast from a config entry."""
43 if entry.data.get(CONF_UPNP_DESC)
is None:
44 hass.config_entries.async_update_entry(
47 CONF_HOST: entry.data[CONF_HOST],
48 CONF_SERIAL: entry.data[
"serial"],
49 CONF_UPNP_DESC: await
get_upnp_desc(hass, entry.data[CONF_HOST]),
53 client = MusicCastDevice(
54 entry.data[CONF_HOST],
56 entry.data[CONF_UPNP_DESC],
59 await coordinator.async_config_entry_first_refresh()
60 coordinator.musiccast.build_capabilities()
62 hass.data.setdefault(DOMAIN, {})
63 hass.data[DOMAIN][entry.entry_id] = coordinator
65 await coordinator.musiccast.device.enable_polling()
67 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
69 entry.async_on_unload(entry.add_update_listener(async_reload_entry))
74 """Unload a config entry."""
75 unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
77 hass.data[DOMAIN][entry.entry_id].musiccast.device.disable_polling()
78 hass.data[DOMAIN].pop(entry.entry_id)
84 """Reload config entry."""
85 await hass.config_entries.async_reload(entry.entry_id)
None async_reload_entry(HomeAssistant hass, ConfigEntry entry)
def get_upnp_desc(HomeAssistant hass, str host)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
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)