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