Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The iotty integration."""
2 
3 from __future__ import annotations
4 
5 from dataclasses import dataclass
6 import logging
7 
8 from iottycloud.device import Device
9 
10 from homeassistant.config_entries import ConfigEntry
11 from homeassistant.const import Platform
12 from homeassistant.core import HomeAssistant
14  OAuth2Session,
15  async_get_config_entry_implementation,
16 )
17 
18 from . import coordinator
19 
20 _LOGGER = logging.getLogger(__name__)
21 
22 PLATFORMS: list[Platform] = [Platform.COVER, Platform.SWITCH]
23 
24 type IottyConfigEntry = ConfigEntry[IottyConfigEntryData]
25 
26 
27 @dataclass
29  """Contains config entry data for iotty."""
30 
31  known_devices: set[Device]
33 
34 
35 async def async_setup_entry(hass: HomeAssistant, entry: IottyConfigEntry) -> bool:
36  """Set up iotty from a config entry."""
37  _LOGGER.debug("async_setup_entry entry_id=%s", entry.entry_id)
38 
39  implementation = await async_get_config_entry_implementation(hass, entry)
40  session = OAuth2Session(hass, entry, implementation)
41 
42  data_update_coordinator = coordinator.IottyDataUpdateCoordinator(
43  hass, entry, session
44  )
45 
46  entry.runtime_data = IottyConfigEntryData(set(), data_update_coordinator)
47 
48  await data_update_coordinator.async_config_entry_first_refresh()
49 
50  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
51  return True
52 
53 
54 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
55  """Unload a config entry."""
56  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:54
bool async_setup_entry(HomeAssistant hass, IottyConfigEntry entry)
Definition: __init__.py:35
AbstractOAuth2Implementation async_get_config_entry_implementation(HomeAssistant hass, config_entries.ConfigEntry config_entry)