2019-02-13 20:21:14 +00:00
|
|
|
"""Support for testing internet speed via Fast.com."""
|
2024-03-08 13:15:26 +00:00
|
|
|
|
2021-07-05 08:19:37 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2019-12-04 14:20:14 +00:00
|
|
|
import logging
|
2019-02-02 05:50:22 +00:00
|
|
|
|
2024-06-03 01:04:35 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2024-01-11 07:27:15 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.start import async_at_started
|
2019-02-02 05:50:22 +00:00
|
|
|
|
2024-06-03 01:04:35 +00:00
|
|
|
from .const import DOMAIN, PLATFORMS
|
2024-03-15 13:42:07 +00:00
|
|
|
from .coordinator import FastdotcomDataUpdateCoordinator
|
2019-02-02 05:50:22 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2023-11-21 08:59:34 +00:00
|
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
2023-12-11 21:28:04 +00:00
|
|
|
"""Set up Fast.com from a config entry."""
|
2024-03-15 13:42:07 +00:00
|
|
|
coordinator = FastdotcomDataUpdateCoordinator(hass)
|
2023-12-11 21:28:04 +00:00
|
|
|
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
|
2023-12-12 20:18:12 +00:00
|
|
|
|
2023-11-21 08:59:34 +00:00
|
|
|
await hass.config_entries.async_forward_entry_setups(
|
|
|
|
entry,
|
|
|
|
PLATFORMS,
|
2022-01-10 09:30:47 +00:00
|
|
|
)
|
2019-02-02 05:50:22 +00:00
|
|
|
|
2024-01-11 07:27:15 +00:00
|
|
|
async def _async_finish_startup(hass: HomeAssistant) -> None:
|
|
|
|
"""Run this only when HA has finished its startup."""
|
|
|
|
await coordinator.async_config_entry_first_refresh()
|
|
|
|
|
|
|
|
# Don't start a speedtest during startup, this will slow down the overall startup dramatically
|
|
|
|
async_at_started(hass, _async_finish_startup)
|
2019-02-02 05:50:22 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
|
2023-11-21 08:59:34 +00:00
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
|
|
"""Unload Fast.com config entry."""
|
|
|
|
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
2023-12-11 21:28:04 +00:00
|
|
|
hass.data[DOMAIN].pop(entry.entry_id)
|
2023-11-21 08:59:34 +00:00
|
|
|
return unload_ok
|