Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The OpenGarage integration."""
2 
3 from __future__ import annotations
4 
5 import opengarage
6 
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.const import CONF_HOST, CONF_PORT, CONF_VERIFY_SSL, Platform
9 from homeassistant.core import HomeAssistant
10 from homeassistant.helpers.aiohttp_client import async_get_clientsession
11 
12 from .const import CONF_DEVICE_KEY, DOMAIN
13 from .coordinator import OpenGarageDataUpdateCoordinator
14 
15 PLATFORMS = [Platform.BINARY_SENSOR, Platform.BUTTON, Platform.COVER, Platform.SENSOR]
16 
17 
18 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
19  """Set up OpenGarage from a config entry."""
20  open_garage_connection = opengarage.OpenGarage(
21  f"{entry.data[CONF_HOST]}:{entry.data[CONF_PORT]}",
22  entry.data[CONF_DEVICE_KEY],
23  entry.data[CONF_VERIFY_SSL],
25  )
26  open_garage_data_coordinator = OpenGarageDataUpdateCoordinator(
27  hass,
28  open_garage_connection=open_garage_connection,
29  )
30  await open_garage_data_coordinator.async_config_entry_first_refresh()
31  hass.data.setdefault(DOMAIN, {})[entry.entry_id] = open_garage_data_coordinator
32 
33  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
34 
35  return True
36 
37 
38 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
39  """Unload a config entry."""
40  unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
41  if unload_ok:
42  hass.data[DOMAIN].pop(entry.entry_id)
43 
44  return unload_ok
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:38
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:18
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)