Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The V2C integration."""
2 
3 from __future__ import annotations
4 
5 from pytrydan import Trydan
6 
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.const import CONF_HOST, Platform
9 from homeassistant.core import HomeAssistant
10 from homeassistant.helpers.httpx_client import get_async_client
11 
12 from .coordinator import V2CUpdateCoordinator
13 
14 PLATFORMS: list[Platform] = [
15  Platform.BINARY_SENSOR,
16  Platform.NUMBER,
17  Platform.SENSOR,
18  Platform.SWITCH,
19 ]
20 
21 
22 type V2CConfigEntry = ConfigEntry[V2CUpdateCoordinator]
23 
24 
25 async def async_setup_entry(hass: HomeAssistant, entry: V2CConfigEntry) -> bool:
26  """Set up V2C from a config entry."""
27 
28  host = entry.data[CONF_HOST]
29  trydan = Trydan(host, get_async_client(hass, verify_ssl=False))
30  coordinator = V2CUpdateCoordinator(hass, trydan, host)
31 
32  await coordinator.async_config_entry_first_refresh()
33 
34  entry.runtime_data = coordinator
35 
36  if coordinator.data.ID and entry.unique_id != coordinator.data.ID:
37  hass.config_entries.async_update_entry(entry, unique_id=coordinator.data.ID)
38 
39  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
40 
41  return True
42 
43 
44 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
45  """Unload a config entry."""
46  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:44
bool async_setup_entry(HomeAssistant hass, V2CConfigEntry entry)
Definition: __init__.py:25
httpx.AsyncClient get_async_client(HomeAssistant hass, bool verify_ssl=True)
Definition: httpx_client.py:41