Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Aussie Broadband integration."""
2 
3 from __future__ import annotations
4 
5 from aiohttp import ClientError
6 from aussiebb.asyncio import AussieBB
7 from aussiebb.const import FETCH_TYPES
8 from aussiebb.exceptions import AuthenticationException
9 
10 from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
11 from homeassistant.core import HomeAssistant
12 from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
13 from homeassistant.helpers.aiohttp_client import async_get_clientsession
14 
15 from .coordinator import (
16  AussieBroadbandConfigEntry,
17  AussieBroadbandDataUpdateCoordinator,
18 )
19 
20 PLATFORMS = [Platform.SENSOR]
21 
22 
24  hass: HomeAssistant, entry: AussieBroadbandConfigEntry
25 ) -> bool:
26  """Set up Aussie Broadband from a config entry."""
27  # Login to the Aussie Broadband API and retrieve the current service list
28  client = AussieBB(
29  entry.data[CONF_USERNAME],
30  entry.data[CONF_PASSWORD],
32  )
33 
34  # Ignore services that don't support usage data
35  ignore_types = [*FETCH_TYPES, "Hardware"]
36 
37  try:
38  await client.login()
39  services = await client.get_services(drop_types=ignore_types)
40  except AuthenticationException as exc:
41  raise ConfigEntryAuthFailed from exc
42  except ClientError as exc:
43  raise ConfigEntryNotReady from exc
44 
45  # Initiate a Data Update Coordinator for each service
46  for service in services:
47  service["coordinator"] = AussieBroadbandDataUpdateCoordinator(
48  hass, client, service["service_id"]
49  )
50  await service["coordinator"].async_config_entry_first_refresh()
51 
52  # Setup the integration
53  entry.runtime_data = services
54  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
55 
56  return True
57 
58 
60  hass: HomeAssistant, entry: AussieBroadbandConfigEntry
61 ) -> bool:
62  """Unload the config entry."""
63  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_setup_entry(HomeAssistant hass, AussieBroadbandConfigEntry entry)
Definition: __init__.py:25
bool async_unload_entry(HomeAssistant hass, AussieBroadbandConfigEntry entry)
Definition: __init__.py:61
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)