Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The PoolSense integration."""
2 
3 import logging
4 
5 from poolsense import PoolSense
6 
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, Platform
9 from homeassistant.core import HomeAssistant
10 from homeassistant.helpers import aiohttp_client
11 
12 from .coordinator import PoolSenseDataUpdateCoordinator
13 
14 type PoolSenseConfigEntry = ConfigEntry[PoolSenseDataUpdateCoordinator]
15 
16 PLATFORMS = [Platform.BINARY_SENSOR, Platform.SENSOR]
17 
18 
19 _LOGGER = logging.getLogger(__name__)
20 
21 
22 async def async_setup_entry(hass: HomeAssistant, entry: PoolSenseConfigEntry) -> bool:
23  """Set up PoolSense from a config entry."""
24 
25  poolsense = PoolSense(
26  aiohttp_client.async_get_clientsession(hass),
27  entry.data[CONF_EMAIL],
28  entry.data[CONF_PASSWORD],
29  )
30  auth_valid = await poolsense.test_poolsense_credentials()
31 
32  if not auth_valid:
33  _LOGGER.error("Invalid authentication")
34  return False
35 
36  coordinator = PoolSenseDataUpdateCoordinator(hass, poolsense)
37 
38  await coordinator.async_config_entry_first_refresh()
39 
40  entry.runtime_data = coordinator
41 
42  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
43 
44  return True
45 
46 
47 async def async_unload_entry(hass: HomeAssistant, entry: PoolSenseConfigEntry) -> bool:
48  """Unload a config entry."""
49  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_unload_entry(HomeAssistant hass, PoolSenseConfigEntry entry)
Definition: __init__.py:47
bool async_setup_entry(HomeAssistant hass, PoolSenseConfigEntry entry)
Definition: __init__.py:22