Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The venstar component."""
2 
3 from __future__ import annotations
4 
5 from venstarcolortouch import VenstarColorTouch
6 
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.const import (
9  CONF_HOST,
10  CONF_PASSWORD,
11  CONF_PIN,
12  CONF_SSL,
13  CONF_USERNAME,
14  Platform,
15 )
16 from homeassistant.core import HomeAssistant
17 
18 from .const import DOMAIN, VENSTAR_TIMEOUT
19 from .coordinator import VenstarDataUpdateCoordinator
20 
21 PLATFORMS = [Platform.BINARY_SENSOR, Platform.CLIMATE, Platform.SENSOR]
22 
23 
24 async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry) -> bool:
25  """Set up the Venstar thermostat."""
26  username = config.data.get(CONF_USERNAME)
27  password = config.data.get(CONF_PASSWORD)
28  pin = config.data.get(CONF_PIN)
29  host = config.data[CONF_HOST]
30  timeout = VENSTAR_TIMEOUT
31  protocol = "https" if config.data[CONF_SSL] else "http"
32 
33  client = VenstarColorTouch(
34  addr=host,
35  timeout=timeout,
36  user=username,
37  password=password,
38  pin=pin,
39  proto=protocol,
40  )
41 
42  venstar_data_coordinator = VenstarDataUpdateCoordinator(
43  hass,
44  venstar_connection=client,
45  )
46  await venstar_data_coordinator.async_config_entry_first_refresh()
47 
48  hass.data.setdefault(DOMAIN, {})[config.entry_id] = venstar_data_coordinator
49  await hass.config_entries.async_forward_entry_setups(config, PLATFORMS)
50 
51  return True
52 
53 
54 async def async_unload_entry(hass: HomeAssistant, config: ConfigEntry) -> bool:
55  """Unload the config and platforms."""
56  unload_ok = await hass.config_entries.async_unload_platforms(config, PLATFORMS)
57  if unload_ok:
58  hass.data[DOMAIN].pop(config.entry_id)
59  return unload_ok
bool async_setup_entry(HomeAssistant hass, ConfigEntry config)
Definition: __init__.py:24
bool async_unload_entry(HomeAssistant hass, ConfigEntry config)
Definition: __init__.py:54