Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Aseko Pool Live integration."""
2 
3 from __future__ import annotations
4 
5 import logging
6 
7 from aioaseko import Aseko, AsekoNotLoggedIn
8 
9 from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, Platform
10 from homeassistant.core import HomeAssistant
11 from homeassistant.exceptions import ConfigEntryAuthFailed
12 
13 from .coordinator import AsekoConfigEntry, AsekoDataUpdateCoordinator
14 
15 _LOGGER = logging.getLogger(__name__)
16 
17 PLATFORMS: list[str] = [Platform.BINARY_SENSOR, Platform.SENSOR]
18 
19 
20 async def async_setup_entry(hass: HomeAssistant, entry: AsekoConfigEntry) -> bool:
21  """Set up Aseko Pool Live from a config entry."""
22  aseko = Aseko(entry.data[CONF_EMAIL], entry.data[CONF_PASSWORD])
23 
24  try:
25  await aseko.login()
26  except AsekoNotLoggedIn as err:
27  raise ConfigEntryAuthFailed from err
28 
29  coordinator = AsekoDataUpdateCoordinator(hass, aseko)
30  await coordinator.async_config_entry_first_refresh()
31  entry.runtime_data = coordinator
32  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
33  return True
34 
35 
36 async def async_unload_entry(hass: HomeAssistant, entry: AsekoConfigEntry) -> bool:
37  """Unload a config entry."""
38  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
39 
40 
42  hass: HomeAssistant, config_entry: AsekoConfigEntry
43 ) -> bool:
44  """Migrate old entry."""
45  _LOGGER.debug("Migrating from version %s", config_entry.version)
46 
47  if config_entry.version == 1:
48  new = {
49  CONF_EMAIL: config_entry.title,
50  CONF_PASSWORD: "",
51  }
52 
53  hass.config_entries.async_update_entry(config_entry, data=new, version=2)
54 
55  _LOGGER.debug("Migration to version %s successful", config_entry.version)
56  return True
57 
58  _LOGGER.error("Attempt to migrate from unknown version %s", config_entry.version)
59  return False
bool async_setup_entry(HomeAssistant hass, AsekoConfigEntry entry)
Definition: __init__.py:20
bool async_migrate_entry(HomeAssistant hass, AsekoConfigEntry config_entry)
Definition: __init__.py:43
bool async_unload_entry(HomeAssistant hass, AsekoConfigEntry entry)
Definition: __init__.py:36