Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The ThermoBeacon integration."""
2 
3 from __future__ import annotations
4 
5 import logging
6 
7 from thermobeacon_ble import ThermoBeaconBluetoothDeviceData
8 
9 from homeassistant.components.bluetooth import BluetoothScanningMode
11  PassiveBluetoothProcessorCoordinator,
12 )
13 from homeassistant.config_entries import ConfigEntry
14 from homeassistant.const import Platform
15 from homeassistant.core import HomeAssistant
16 
17 from .const import DOMAIN
18 
19 PLATFORMS: list[Platform] = [Platform.SENSOR]
20 
21 _LOGGER = logging.getLogger(__name__)
22 
23 
24 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
25  """Set up ThermoBeacon BLE device from a config entry."""
26  address = entry.unique_id
27  assert address is not None
28  data = ThermoBeaconBluetoothDeviceData()
29  coordinator = hass.data.setdefault(DOMAIN, {})[entry.entry_id] = (
31  hass,
32  _LOGGER,
33  address=address,
34  mode=BluetoothScanningMode.PASSIVE,
35  update_method=data.update,
36  )
37  )
38  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
39  entry.async_on_unload(
40  coordinator.async_start()
41  ) # only start after all platforms have had a chance to subscribe
42  return True
43 
44 
45 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
46  """Unload a config entry."""
47  if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
48  hass.data[DOMAIN].pop(entry.entry_id)
49 
50  return unload_ok
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:24
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:45