Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Ondilo ICO integration."""
2 
3 from homeassistant.config_entries import ConfigEntry
4 from homeassistant.const import Platform
5 from homeassistant.core import HomeAssistant
6 from homeassistant.helpers import config_entry_oauth2_flow
7 
8 from .api import OndiloClient
9 from .config_flow import OndiloIcoOAuth2FlowHandler
10 from .const import DOMAIN
11 from .coordinator import OndiloIcoCoordinator
12 from .oauth_impl import OndiloOauth2Implementation
13 
14 PLATFORMS = [Platform.SENSOR]
15 
16 
17 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
18  """Set up Ondilo ICO from a config entry."""
19 
20  OndiloIcoOAuth2FlowHandler.async_register_implementation(
21  hass,
23  )
24 
25  implementation = (
26  await config_entry_oauth2_flow.async_get_config_entry_implementation(
27  hass, entry
28  )
29  )
30 
31  coordinator = OndiloIcoCoordinator(hass, OndiloClient(hass, entry, implementation))
32 
33  await coordinator.async_config_entry_first_refresh()
34 
35  hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
36 
37  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
38 
39  return True
40 
41 
42 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
43  """Unload a config entry."""
44  unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
45  if unload_ok:
46  hass.data[DOMAIN].pop(entry.entry_id)
47 
48  return unload_ok
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:17
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:42