Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Starlink integration."""
2 
3 from __future__ import annotations
4 
5 from homeassistant.config_entries import ConfigEntry
6 from homeassistant.const import CONF_IP_ADDRESS, Platform
7 from homeassistant.core import HomeAssistant
8 
9 from .const import DOMAIN
10 from .coordinator import StarlinkUpdateCoordinator
11 
12 PLATFORMS = [
13  Platform.BINARY_SENSOR,
14  Platform.BUTTON,
15  Platform.DEVICE_TRACKER,
16  Platform.SENSOR,
17  Platform.SWITCH,
18  Platform.TIME,
19 ]
20 
21 
22 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
23  """Set up Starlink from a config entry."""
24  coordinator = StarlinkUpdateCoordinator(
25  hass=hass,
26  url=entry.data[CONF_IP_ADDRESS],
27  name=entry.title,
28  )
29 
30  await coordinator.async_config_entry_first_refresh()
31 
32  hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
33 
34  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
35  return True
36 
37 
38 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
39  """Unload a config entry."""
40  if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
41  hass.data[DOMAIN].pop(entry.entry_id)
42 
43  return unload_ok