52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
"""Support for testing internet speed via Fast.com."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.core import HomeAssistant
|
|
import homeassistant.helpers.config_validation as cv
|
|
from homeassistant.helpers.start import async_at_started
|
|
from homeassistant.helpers.typing import ConfigType
|
|
|
|
from .const import DOMAIN, PLATFORMS
|
|
from .coordinator import FastdotcomDataUpdateCoordinator
|
|
from .services import async_setup_services
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
|
|
|
|
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|
"""Set up the Fastdotcom component."""
|
|
async_setup_services(hass)
|
|
return True
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
"""Set up Fast.com from a config entry."""
|
|
coordinator = FastdotcomDataUpdateCoordinator(hass)
|
|
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
|
|
|
|
await hass.config_entries.async_forward_entry_setups(
|
|
entry,
|
|
PLATFORMS,
|
|
)
|
|
|
|
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)
|
|
return True
|
|
|
|
|
|
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):
|
|
hass.data[DOMAIN].pop(entry.entry_id)
|
|
return unload_ok
|