Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Version integration."""
2 
3 from __future__ import annotations
4 
5 import logging
6 
7 from pyhaversion import HaVersion
8 
9 from homeassistant.config_entries import ConfigEntry
10 from homeassistant.core import HomeAssistant
11 from homeassistant.helpers.aiohttp_client import async_get_clientsession
12 
13 from .const import (
14  BOARD_MAP,
15  CONF_BOARD,
16  CONF_CHANNEL,
17  CONF_IMAGE,
18  CONF_SOURCE,
19  PLATFORMS,
20 )
21 from .coordinator import VersionDataUpdateCoordinator
22 
23 _LOGGER = logging.getLogger(__name__)
24 
25 type VersionConfigEntry = ConfigEntry[VersionDataUpdateCoordinator]
26 
27 
28 async def async_setup_entry(hass: HomeAssistant, entry: VersionConfigEntry) -> bool:
29  """Set up the version integration from a config entry."""
30 
31  board = entry.data[CONF_BOARD]
32 
33  if board not in BOARD_MAP:
34  _LOGGER.error(
35  'Board "%s" is (no longer) valid. Please remove the integration "%s"',
36  board,
37  entry.title,
38  )
39  return False
40 
41  coordinator = VersionDataUpdateCoordinator(
42  hass=hass,
43  api=HaVersion(
44  session=async_get_clientsession(hass),
45  source=entry.data[CONF_SOURCE],
46  image=entry.data[CONF_IMAGE],
47  board=BOARD_MAP[board],
48  channel=entry.data[CONF_CHANNEL].lower(),
49  timeout=30,
50  ),
51  )
52  await coordinator.async_config_entry_first_refresh()
53 
54  entry.runtime_data = coordinator
55  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
56 
57  return True
58 
59 
60 async def async_unload_entry(hass: HomeAssistant, entry: VersionConfigEntry) -> bool:
61  """Unload the config entry."""
62  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_unload_entry(HomeAssistant hass, VersionConfigEntry entry)
Definition: __init__.py:60
bool async_setup_entry(HomeAssistant hass, VersionConfigEntry entry)
Definition: __init__.py:28
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)