Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Airtouch 5 integration."""
2 
3 from __future__ import annotations
4 
5 from airtouch5py.airtouch5_simple_client import Airtouch5SimpleClient
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.exceptions import ConfigEntryNotReady
11 
12 PLATFORMS: list[Platform] = [Platform.CLIMATE, Platform.COVER]
13 
14 type Airtouch5ConfigEntry = ConfigEntry[Airtouch5SimpleClient]
15 
16 
17 async def async_setup_entry(hass: HomeAssistant, entry: Airtouch5ConfigEntry) -> bool:
18  """Set up Airtouch 5 from a config entry."""
19 
20  # Create API instance
21  host = entry.data[CONF_HOST]
22  client = Airtouch5SimpleClient(host)
23 
24  # Connect to the API
25  try:
26  await client.connect_and_stay_connected()
27  except TimeoutError as t:
28  raise ConfigEntryNotReady from t
29 
30  # Store an API object for your platforms to access
31  entry.runtime_data = client
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: Airtouch5ConfigEntry) -> bool:
39  """Unload a config entry."""
40  if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
41  client = entry.runtime_data
42  await client.disconnect()
43  client.ac_status_callbacks.clear()
44  client.connection_state_callbacks.clear()
45  client.data_packet_callbacks.clear()
46  client.zone_status_callbacks.clear()
47 
48  return unload_ok
bool async_unload_entry(HomeAssistant hass, Airtouch5ConfigEntry entry)
Definition: __init__.py:38
bool async_setup_entry(HomeAssistant hass, Airtouch5ConfigEntry entry)
Definition: __init__.py:17