Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """Support for testing internet speed via Fast.com."""
2 
3 from __future__ import annotations
4 
5 import logging
6 
7 from homeassistant.config_entries import ConfigEntry, ConfigEntryState
8 from homeassistant.core import HomeAssistant
9 from homeassistant.helpers.start import async_at_started
10 
11 from .const import DOMAIN, PLATFORMS
12 from .coordinator import FastdotcomDataUpdateCoordinator
13 
14 _LOGGER = logging.getLogger(__name__)
15 
16 
17 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
18  """Set up Fast.com from a config entry."""
19  coordinator = FastdotcomDataUpdateCoordinator(hass)
20  hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
21 
22  await hass.config_entries.async_forward_entry_setups(
23  entry,
24  PLATFORMS,
25  )
26 
27  async def _async_finish_startup(hass: HomeAssistant) -> None:
28  """Run this only when HA has finished its startup."""
29  if entry.state == ConfigEntryState.LOADED:
30  await coordinator.async_refresh()
31  else:
32  await coordinator.async_config_entry_first_refresh()
33 
34  # Don't start a speedtest during startup, this will slow down the overall startup dramatically
35  async_at_started(hass, _async_finish_startup)
36  return True
37 
38 
39 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
40  """Unload Fast.com config entry."""
41  if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
42  hass.data[DOMAIN].pop(entry.entry_id)
43  return unload_ok
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:17
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:39
CALLBACK_TYPE async_at_started(HomeAssistant hass, Callable[[HomeAssistant], Coroutine[Any, Any, None]|None] at_start_cb)
Definition: start.py:80