Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """Support for LaMetric time."""
2 
3 from homeassistant.components import notify as hass_notify
4 from homeassistant.config_entries import ConfigEntry
5 from homeassistant.const import CONF_NAME, Platform
6 from homeassistant.core import HomeAssistant
7 from homeassistant.helpers import discovery
9 from homeassistant.helpers.typing import ConfigType
10 
11 from .const import DOMAIN, PLATFORMS
12 from .coordinator import LaMetricDataUpdateCoordinator
13 from .services import async_setup_services
14 
15 CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
16 
17 
18 async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
19  """Set up the LaMetric integration."""
21  hass.data[DOMAIN] = {"hass_config": config}
22  return True
23 
24 
25 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
26  """Set up LaMetric from a config entry."""
27  coordinator = LaMetricDataUpdateCoordinator(hass, entry)
28  await coordinator.async_config_entry_first_refresh()
29 
30  hass.data[DOMAIN][entry.entry_id] = coordinator
31  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
32 
33  # Set up notify platform, no entry support for notify component yet,
34  # have to use discovery to load platform.
35  hass.async_create_task(
36  discovery.async_load_platform(
37  hass,
38  Platform.NOTIFY,
39  DOMAIN,
40  {CONF_NAME: coordinator.data.name, "entry_id": entry.entry_id},
41  hass.data[DOMAIN]["hass_config"],
42  )
43  )
44  return True
45 
46 
47 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
48  """Unload LaMetric config entry."""
49  if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
50  del hass.data[DOMAIN][entry.entry_id]
51  await hass_notify.async_reload(hass, DOMAIN)
52  return unload_ok
None async_setup_services(HomeAssistant hass)
Definition: __init__.py:72
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:25
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:47
bool async_setup(HomeAssistant hass, ConfigType config)
Definition: __init__.py:18