Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The EnergyZero integration."""
2 
3 from __future__ import annotations
4 
5 from homeassistant.config_entries import ConfigEntry
6 from homeassistant.const import Platform
7 from homeassistant.core import HomeAssistant
8 from homeassistant.exceptions import ConfigEntryNotReady
9 from homeassistant.helpers import config_validation as cv
10 from homeassistant.helpers.typing import ConfigType
11 
12 from .const import DOMAIN
13 from .coordinator import EnergyZeroDataUpdateCoordinator
14 from .services import async_setup_services
15 
16 PLATFORMS = [Platform.SENSOR]
17 CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
18 
19 
20 async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
21  """Set up EnergyZero services."""
22 
24 
25  return True
26 
27 
28 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
29  """Set up EnergyZero from a config entry."""
30 
31  coordinator = EnergyZeroDataUpdateCoordinator(hass)
32  try:
33  await coordinator.async_config_entry_first_refresh()
34  except ConfigEntryNotReady:
35  await coordinator.energyzero.close()
36  raise
37 
38  hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
39 
40  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
41 
42  return True
43 
44 
45 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
46  """Unload EnergyZero config entry."""
47  if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
48  hass.data[DOMAIN].pop(entry.entry_id)
49  return unload_ok
bool async_setup(HomeAssistant hass, ConfigType config)
Definition: __init__.py:20
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:45
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:28
None async_setup_services(HomeAssistant hass)
Definition: __init__.py:72