1 """The govee Bluetooth integration."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from logging
import Logger
8 from govee_ble
import GoveeBluetoothDeviceData, ModelInfo, SensorUpdate, get_model_info
11 BluetoothScanningMode,
12 BluetoothServiceInfoBleak,
15 PassiveBluetoothDataProcessor,
16 PassiveBluetoothProcessorCoordinator,
22 from .const
import CONF_DEVICE_TYPE, DOMAIN
24 type GoveeBLEConfigEntry = ConfigEntry[GoveeBLEBluetoothProcessorCoordinator]
29 entry: GoveeBLEConfigEntry,
30 service_info: BluetoothServiceInfoBleak,
32 """Process a BluetoothServiceInfoBleak, running side effects and returning sensor data."""
33 coordinator = entry.runtime_data
34 data = coordinator.device_data
35 update = data.update(service_info)
36 if not coordinator.model_info
and (device_type := data.device_type):
37 hass.config_entries.async_update_entry(
38 entry, data={**entry.data, CONF_DEVICE_TYPE: device_type}
40 coordinator.set_model_info(device_type)
41 if update.events
and hass.state
is CoreState.running:
43 address = service_info.device.address
44 for event
in update.events.values():
45 key = event.device_key.key
53 """Format an event dispatcher name."""
54 return f
"{DOMAIN}_{address}_{key}"
58 PassiveBluetoothProcessorCoordinator[SensorUpdate]
60 """Define a govee ble Bluetooth Passive Update Processor Coordinator."""
67 mode: BluetoothScanningMode,
68 update_method: Callable[[BluetoothServiceInfoBleak], SensorUpdate],
69 device_data: GoveeBluetoothDeviceData,
72 """Initialize the Govee BLE Bluetooth Passive Update Processor Coordinator."""
73 super().
__init__(hass, logger, address, mode, update_method)
76 self.
model_infomodel_info: ModelInfo |
None =
None
77 if device_type := entry.data.get(CONF_DEVICE_TYPE):
81 """Set the model info."""
86 PassiveBluetoothDataProcessor[_T, SensorUpdate]
88 """Define a govee-ble Bluetooth Passive Update Data Processor."""
90 coordinator: GoveeBLEBluetoothProcessorCoordinator
None __init__(self, HomeAssistant hass, Logger logger, str address, BluetoothScanningMode mode, Callable[[BluetoothServiceInfoBleak], SensorUpdate] update_method, GoveeBluetoothDeviceData device_data, ConfigEntry entry)
None set_model_info(self, str device_type)
SensorUpdate process_service_info(HomeAssistant hass, GoveeBLEConfigEntry entry, BluetoothServiceInfoBleak service_info)
str format_event_dispatcher_name(str address, str key)
None async_dispatcher_send(HomeAssistant hass, str signal, *Any args)