Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """Integration for Tailwind devices."""
2 
3 from __future__ import annotations
4 
5 from homeassistant.config_entries import ConfigEntry
6 from homeassistant.const import Platform
7 from homeassistant.core import HomeAssistant
8 from homeassistant.helpers import device_registry as dr
9 
10 from .const import DOMAIN
11 from .coordinator import TailwindDataUpdateCoordinator
12 from .typing import TailwindConfigEntry
13 
14 PLATFORMS = [Platform.BINARY_SENSOR, Platform.BUTTON, Platform.COVER, Platform.NUMBER]
15 
16 
17 async def async_setup_entry(hass: HomeAssistant, entry: TailwindConfigEntry) -> bool:
18  """Set up Tailwind device from a config entry."""
19  coordinator = TailwindDataUpdateCoordinator(hass, entry)
20  await coordinator.async_config_entry_first_refresh()
21 
22  entry.runtime_data = coordinator
23 
24  # Register the Tailwind device, since other entities will have it as a parent.
25  # This prevents a child device being created before the parent ending up
26  # with a missing via_device.
27  device_registry = dr.async_get(hass)
28  device_registry.async_get_or_create(
29  config_entry_id=entry.entry_id,
30  identifiers={(DOMAIN, coordinator.data.device_id)},
31  connections={(dr.CONNECTION_NETWORK_MAC, coordinator.data.mac_address)},
32  manufacturer="Tailwind",
33  model=coordinator.data.product,
34  sw_version=coordinator.data.firmware_version,
35  )
36 
37  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
38 
39  return True
40 
41 
42 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
43  """Unload Tailwind config entry."""
44  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_setup_entry(HomeAssistant hass, TailwindConfigEntry entry)
Definition: __init__.py:17
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:42