Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Wallbox integration."""
2 
3 from __future__ import annotations
4 
5 from wallbox import Wallbox
6 
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
9 from homeassistant.core import HomeAssistant
10 from homeassistant.exceptions import ConfigEntryAuthFailed
11 
12 from .const import CONF_STATION, DOMAIN, UPDATE_INTERVAL
13 from .coordinator import InvalidAuth, WallboxCoordinator, async_validate_input
14 
15 PLATFORMS = [Platform.LOCK, Platform.NUMBER, Platform.SENSOR, Platform.SWITCH]
16 
17 
18 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
19  """Set up Wallbox from a config entry."""
20  wallbox = Wallbox(
21  entry.data[CONF_USERNAME],
22  entry.data[CONF_PASSWORD],
23  jwtTokenDrift=UPDATE_INTERVAL,
24  )
25  try:
26  await async_validate_input(hass, wallbox)
27  except InvalidAuth as ex:
28  raise ConfigEntryAuthFailed from ex
29 
30  wallbox_coordinator = WallboxCoordinator(
31  entry.data[CONF_STATION],
32  wallbox,
33  hass,
34  )
35  await wallbox_coordinator.async_config_entry_first_refresh()
36 
37  hass.data.setdefault(DOMAIN, {})[entry.entry_id] = wallbox_coordinator
38 
39  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
40 
41  return True
42 
43 
44 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
45  """Unload a config entry."""
46  unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
47  if unload_ok:
48  hass.data[DOMAIN].pop(entry.entry_id)
49 
50  return unload_ok
dict[str, Any] async_validate_input(dict[str, Any] data, AugustGateway august_gateway)
Definition: config_flow.py:42
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:44
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:18