Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The SensorPush Bluetooth integration."""
2 
3 from __future__ import annotations
4 
5 import logging
6 
7 from sensorpush_ble import SensorPushBluetoothDeviceData
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.SENSOR]
18 
19 _LOGGER = logging.getLogger(__name__)
20 
21 type SensorPushConfigEntry = ConfigEntry[PassiveBluetoothProcessorCoordinator]
22 
23 
24 async def async_setup_entry(hass: HomeAssistant, entry: SensorPushConfigEntry) -> bool:
25  """Set up SensorPush BLE device from a config entry."""
26  address = entry.unique_id
27  assert address is not None
29  hass,
30  _LOGGER,
31  address=address,
32  mode=BluetoothScanningMode.PASSIVE,
33  update_method=SensorPushBluetoothDeviceData().update,
34  )
35  entry.runtime_data = coordinator
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: ConfigEntry) -> bool:
43  """Unload a config entry."""
44  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:42
bool async_setup_entry(HomeAssistant hass, SensorPushConfigEntry entry)
Definition: __init__.py:24