Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The cert_expiry component."""
2 
3 from __future__ import annotations
4 
5 from homeassistant.config_entries import ConfigEntry
6 from homeassistant.const import CONF_HOST, CONF_PORT, Platform
7 from homeassistant.core import HomeAssistant
8 from homeassistant.helpers.start import async_at_started
9 
10 from .coordinator import CertExpiryDataUpdateCoordinator
11 
12 PLATFORMS = [Platform.SENSOR]
13 
14 type CertExpiryConfigEntry = ConfigEntry[CertExpiryDataUpdateCoordinator]
15 
16 
17 async def async_setup_entry(hass: HomeAssistant, entry: CertExpiryConfigEntry) -> bool:
18  """Load the saved entities."""
19  host: str = entry.data[CONF_HOST]
20  port: int = entry.data[CONF_PORT]
21 
22  coordinator = CertExpiryDataUpdateCoordinator(hass, host, port)
23 
24  entry.runtime_data = coordinator
25 
26  if entry.unique_id is None:
27  hass.config_entries.async_update_entry(entry, unique_id=f"{host}:{port}")
28 
29  async def _async_finish_startup(_: HomeAssistant) -> None:
30  await coordinator.async_refresh()
31  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
32 
33  async_at_started(hass, _async_finish_startup)
34  return True
35 
36 
37 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
38  """Unload a config entry."""
39  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:37
bool async_setup_entry(HomeAssistant hass, CertExpiryConfigEntry entry)
Definition: __init__.py:17
CALLBACK_TYPE async_at_started(HomeAssistant hass, Callable[[HomeAssistant], Coroutine[Any, Any, None]|None] at_start_cb)
Definition: start.py:80