Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Qingping integration."""
2 
3 from __future__ import annotations
4 
5 import logging
6 
7 from qingping_ble import QingpingBluetoothDeviceData
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 PLATFORMS: list[Platform] = [Platform.BINARY_SENSOR, Platform.SENSOR]
18 
19 _LOGGER = logging.getLogger(__name__)
20 
21 type QingpingConfigEntry = ConfigEntry[PassiveBluetoothProcessorCoordinator]
22 
23 
24 async def async_setup_entry(hass: HomeAssistant, entry: QingpingConfigEntry) -> bool:
25  """Set up Qingping BLE device from a config entry."""
26  address = entry.unique_id
27  assert address is not None
28  data = QingpingBluetoothDeviceData()
29  coordinator = entry.runtime_data = PassiveBluetoothProcessorCoordinator(
30  hass,
31  _LOGGER,
32  address=address,
33  mode=BluetoothScanningMode.PASSIVE,
34  update_method=data.update,
35  )
36  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
37  # only start after all platforms have had a chance to subscribe
38  entry.async_on_unload(coordinator.async_start())
39  return True
40 
41 
42 async def async_unload_entry(hass: HomeAssistant, entry: QingpingConfigEntry) -> bool:
43  """Unload a config entry."""
44  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_unload_entry(HomeAssistant hass, QingpingConfigEntry entry)
Definition: __init__.py:42
bool async_setup_entry(HomeAssistant hass, QingpingConfigEntry entry)
Definition: __init__.py:24