Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Monzo 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.helpers.aiohttp_client import async_get_clientsession
10  OAuth2Session,
11  async_get_config_entry_implementation,
12 )
13 
14 from .api import AuthenticatedMonzoAPI
15 from .const import DOMAIN
16 from .coordinator import MonzoCoordinator
17 
18 PLATFORMS: list[Platform] = [Platform.SENSOR]
19 
20 
21 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
22  """Set up Monzo from a config entry."""
23  implementation = await async_get_config_entry_implementation(hass, entry)
24 
25  session = OAuth2Session(hass, entry, implementation)
26 
27  external_api = AuthenticatedMonzoAPI(async_get_clientsession(hass), session)
28 
29  coordinator = MonzoCoordinator(hass, external_api)
30 
31  await coordinator.async_config_entry_first_refresh()
32 
33  hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
34  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
35 
36  return True
37 
38 
39 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
40  """Unload a config entry."""
41  unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
42  if unload_ok:
43  hass.data[DOMAIN].pop(entry.entry_id)
44  return unload_ok
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:39
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:21
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)
AbstractOAuth2Implementation async_get_config_entry_implementation(HomeAssistant hass, config_entries.ConfigEntry config_entry)