Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """SMLIGHT SLZB Zigbee device integration."""
2 
3 from __future__ import annotations
4 
5 from dataclasses import dataclass
6 
7 from pysmlight import Api2
8 
9 from homeassistant.config_entries import ConfigEntry
10 from homeassistant.const import CONF_HOST, Platform
11 from homeassistant.core import HomeAssistant
12 from homeassistant.helpers.aiohttp_client import async_get_clientsession
13 
14 from .coordinator import SmDataUpdateCoordinator, SmFirmwareUpdateCoordinator
15 
16 PLATFORMS: list[Platform] = [
17  Platform.BINARY_SENSOR,
18  Platform.BUTTON,
19  Platform.SENSOR,
20  Platform.SWITCH,
21  Platform.UPDATE,
22 ]
23 
24 
25 @dataclass(kw_only=True)
27  """Coordinator data class."""
28 
29  data: SmDataUpdateCoordinator
30  firmware: SmFirmwareUpdateCoordinator
31 
32 
33 type SmConfigEntry = ConfigEntry[SmlightData]
34 
35 
36 async def async_setup_entry(hass: HomeAssistant, entry: SmConfigEntry) -> bool:
37  """Set up SMLIGHT Zigbee from a config entry."""
38  client = Api2(host=entry.data[CONF_HOST], session=async_get_clientsession(hass))
39 
40  data_coordinator = SmDataUpdateCoordinator(hass, entry.data[CONF_HOST], client)
41  firmware_coordinator = SmFirmwareUpdateCoordinator(
42  hass, entry.data[CONF_HOST], client
43  )
44 
45  await data_coordinator.async_config_entry_first_refresh()
46  await firmware_coordinator.async_config_entry_first_refresh()
47 
48  if data_coordinator.data.info.legacy_api < 2:
49  entry.async_create_background_task(
50  hass, client.sse.client(), "smlight-sse-client"
51  )
52 
53  entry.runtime_data = SmlightData(
54  data=data_coordinator, firmware=firmware_coordinator
55  )
56 
57  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
58  return True
59 
60 
61 async def async_unload_entry(hass: HomeAssistant, entry: SmConfigEntry) -> bool:
62  """Unload a config entry."""
63  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_setup_entry(HomeAssistant hass, SmConfigEntry entry)
Definition: __init__.py:36
bool async_unload_entry(HomeAssistant hass, SmConfigEntry entry)
Definition: __init__.py:61
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)