1 """The OralB integration."""
3 from __future__
import annotations
7 from oralb_ble
import OralBBluetoothDeviceData, SensorUpdate
10 BluetoothScanningMode,
11 BluetoothServiceInfoBleak,
12 async_ble_device_from_address,
15 ActiveBluetoothProcessorCoordinator,
21 PLATFORMS: list[Platform] = [Platform.SENSOR]
23 _LOGGER = logging.getLogger(__name__)
26 type OralBConfigEntry = ConfigEntry[ActiveBluetoothProcessorCoordinator]
30 """Set up OralB BLE device from a config entry."""
31 address = entry.unique_id
32 assert address
is not None
33 data = OralBBluetoothDeviceData()
36 service_info: BluetoothServiceInfoBleak, last_poll: float |
None
41 hass.state
is CoreState.running
42 and data.poll_needed(service_info, last_poll)
45 hass, service_info.device.address, connectable=
True
50 async
def _async_poll(service_info: BluetoothServiceInfoBleak) -> SensorUpdate:
55 if service_info.connectable:
56 connectable_device = service_info.device
58 hass, service_info.device.address,
True
60 connectable_device = device
65 f
"No connectable device found for {service_info.device.address}"
67 return await data.async_poll(connectable_device)
73 mode=BluetoothScanningMode.PASSIVE,
74 update_method=data.update,
75 needs_poll_method=_needs_poll,
76 poll_method=_async_poll,
82 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
84 entry.async_on_unload(coordinator.async_start())
89 """Unload a config entry."""
90 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
BLEDevice|None async_ble_device_from_address(HomeAssistant hass, str address, bool connectable=True)
bool async_unload_entry(HomeAssistant hass, OralBConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, OralBConfigEntry entry)