Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The WiLight integration."""
2 
3 from homeassistant.config_entries import ConfigEntry
4 from homeassistant.const import Platform
5 from homeassistant.core import HomeAssistant
6 from homeassistant.exceptions import ConfigEntryNotReady
7 
8 from .const import DOMAIN
9 from .parent_device import WiLightParent
10 
11 # List the platforms that you want to support.
12 PLATFORMS = [Platform.COVER, Platform.FAN, Platform.LIGHT, Platform.SWITCH]
13 
14 
15 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
16  """Set up a wilight config entry."""
17 
18  parent = WiLightParent(hass, entry)
19 
20  if not await parent.async_setup():
21  raise ConfigEntryNotReady
22 
23  hass.data.setdefault(DOMAIN, {})
24  hass.data[DOMAIN][entry.entry_id] = parent
25 
26  # Set up all platforms for this device/entry.
27  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
28 
29  return True
30 
31 
32 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
33  """Unload WiLight config entry."""
34 
35  # Unload entities for this entry/device.
36  unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
37 
38  # Cleanup
39  parent = hass.data[DOMAIN][entry.entry_id]
40  await parent.async_reset()
41  del hass.data[DOMAIN][entry.entry_id]
42 
43  return unload_ok
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:32
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:15