Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """SlimProto Player integration."""
2 
3 from __future__ import annotations
4 
5 from aioslimproto import SlimServer
6 
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.const import EVENT_HOMEASSISTANT_STOP, Platform
9 from homeassistant.core import Event, HomeAssistant
10 from homeassistant.helpers import device_registry as dr
11 
12 from .const import DOMAIN
13 
14 PLATFORMS = [Platform.MEDIA_PLAYER]
15 
16 
17 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
18  """Set up from a config entry."""
19  slimserver = SlimServer()
20  await slimserver.start()
21 
22  hass.data[DOMAIN] = slimserver
23 
24  # initialize platform(s)
25  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
26 
27  # setup event listeners
28  async def on_hass_stop(event: Event) -> None:
29  """Handle incoming stop event from Home Assistant."""
30  await slimserver.stop()
31 
32  entry.async_on_unload(
33  hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, on_hass_stop)
34  )
35 
36  return True
37 
38 
40  hass: HomeAssistant, config_entry: ConfigEntry, device_entry: dr.DeviceEntry
41 ) -> bool:
42  """Remove a config entry from a device."""
43  return True
44 
45 
46 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
47  """Unload a config entry."""
48  unload_success = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
49  if unload_success:
50  await hass.data.pop(DOMAIN).stop()
51  return unload_success
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:46
bool async_remove_config_entry_device(HomeAssistant hass, ConfigEntry config_entry, dr.DeviceEntry device_entry)
Definition: __init__.py:41
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:17