2024-01-23 13:49:47 +00:00
|
|
|
"""The Airtouch 5 integration."""
|
2024-03-08 13:51:32 +00:00
|
|
|
|
2024-01-23 13:49:47 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from airtouch5py.airtouch5_simple_client import Airtouch5SimpleClient
|
|
|
|
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.const import CONF_HOST, Platform
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.exceptions import ConfigEntryNotReady
|
|
|
|
|
|
|
|
from .const import DOMAIN
|
|
|
|
|
|
|
|
PLATFORMS: list[Platform] = [Platform.CLIMATE]
|
|
|
|
|
2024-05-17 13:42:58 +00:00
|
|
|
type Airtouch5ConfigEntry = ConfigEntry[Airtouch5SimpleClient]
|
2024-01-23 13:49:47 +00:00
|
|
|
|
2024-05-02 16:36:35 +00:00
|
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: Airtouch5ConfigEntry) -> bool:
|
2024-01-23 13:49:47 +00:00
|
|
|
"""Set up Airtouch 5 from a config entry."""
|
|
|
|
|
|
|
|
hass.data.setdefault(DOMAIN, {})
|
|
|
|
|
|
|
|
# Create API instance
|
|
|
|
host = entry.data[CONF_HOST]
|
|
|
|
client = Airtouch5SimpleClient(host)
|
|
|
|
|
|
|
|
# Connect to the API
|
|
|
|
try:
|
|
|
|
await client.connect_and_stay_connected()
|
|
|
|
except TimeoutError as t:
|
2024-03-17 23:40:38 +00:00
|
|
|
raise ConfigEntryNotReady from t
|
2024-01-23 13:49:47 +00:00
|
|
|
|
|
|
|
# Store an API object for your platforms to access
|
2024-05-02 16:36:35 +00:00
|
|
|
entry.runtime_data = client
|
2024-01-23 13:49:47 +00:00
|
|
|
|
|
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2024-05-02 16:36:35 +00:00
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: Airtouch5ConfigEntry) -> bool:
|
2024-01-23 13:49:47 +00:00
|
|
|
"""Unload a config entry."""
|
|
|
|
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
2024-05-02 16:36:35 +00:00
|
|
|
client = entry.runtime_data
|
2024-01-23 13:49:47 +00:00
|
|
|
await client.disconnect()
|
|
|
|
client.ac_status_callbacks.clear()
|
|
|
|
client.connection_state_callbacks.clear()
|
|
|
|
client.data_packet_callbacks.clear()
|
|
|
|
client.zone_status_callbacks.clear()
|
|
|
|
|
|
|
|
return unload_ok
|