Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Geocaching integration."""
2 
3 from homeassistant.config_entries import ConfigEntry
4 from homeassistant.const import Platform
5 from homeassistant.core import HomeAssistant
7  OAuth2Session,
8  async_get_config_entry_implementation,
9 )
10 
11 from .const import DOMAIN
12 from .coordinator import GeocachingDataUpdateCoordinator
13 
14 PLATFORMS = [Platform.SENSOR]
15 
16 
17 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
18  """Set up Geocaching from a config entry."""
19  implementation = await async_get_config_entry_implementation(hass, entry)
20 
21  oauth_session = OAuth2Session(hass, entry, implementation)
22  coordinator = GeocachingDataUpdateCoordinator(
23  hass, entry=entry, session=oauth_session
24  )
25 
26  await coordinator.async_config_entry_first_refresh()
27 
28  hass.data.setdefault(DOMAIN, {})
29  hass.data[DOMAIN][entry.entry_id] = coordinator
30  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
31 
32  return True
33 
34 
35 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
36  """Unload a config entry."""
37  if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
38  del hass.data[DOMAIN][entry.entry_id]
39  return unload_ok
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:35
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:17
AbstractOAuth2Implementation async_get_config_entry_implementation(HomeAssistant hass, config_entries.ConfigEntry config_entry)