Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Govee Bluetooth BLE integration."""
2 
3 from __future__ import annotations
4 
5 from functools import partial
6 import logging
7 
8 from govee_ble import GoveeBluetoothDeviceData
9 
10 from homeassistant.components.bluetooth import BluetoothScanningMode
11 from homeassistant.const import Platform
12 from homeassistant.core import HomeAssistant
13 
14 from .coordinator import (
15  GoveeBLEBluetoothProcessorCoordinator,
16  GoveeBLEConfigEntry,
17  process_service_info,
18 )
19 
20 PLATFORMS: list[Platform] = [Platform.BINARY_SENSOR, Platform.EVENT, Platform.SENSOR]
21 
22 _LOGGER = logging.getLogger(__name__)
23 
24 
25 async def async_setup_entry(hass: HomeAssistant, entry: GoveeBLEConfigEntry) -> bool:
26  """Set up Govee BLE device from a config entry."""
27  address = entry.unique_id
28  assert address is not None
29  data = GoveeBluetoothDeviceData()
30  entry.runtime_data = coordinator = GoveeBLEBluetoothProcessorCoordinator(
31  hass,
32  _LOGGER,
33  address=address,
34  mode=BluetoothScanningMode.ACTIVE,
35  update_method=partial(process_service_info, hass, entry),
36  device_data=data,
37  entry=entry,
38  )
39  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
40  # only start after all platforms have had a chance to subscribe
41  entry.async_on_unload(coordinator.async_start())
42  return True
43 
44 
45 async def async_unload_entry(hass: HomeAssistant, entry: GoveeBLEConfigEntry) -> bool:
46  """Unload a config entry."""
47  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_unload_entry(HomeAssistant hass, GoveeBLEConfigEntry entry)
Definition: __init__.py:45
bool async_setup_entry(HomeAssistant hass, GoveeBLEConfigEntry entry)
Definition: __init__.py:25