You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importasynciofromhomeassistant.componentsimportbluetoothfromhomeassistant.components.bluetoothimportBluetoothChange, BluetoothServiceInfoBleakfromhomeassistant.coreimportcallbackTARGET_DEVICE_ADDRESS="11:22:33:44:55:66"@callbackasyncdef_async_discovered_device(service_info: BluetoothServiceInfoBleak, change: BluetoothChange) ->None:
"""Callback function to handle discovered Bluetooth devices."""log.info(f"Bluetooth device discovered: {service_info.name} at {service_info.address}, Change type: {change}")
@serviceasyncdefble_scan(action=None, id=None):
"""Register the Bluetooth callback function."""try:
cancel_callback=bluetooth.async_register_callback(
hass,
_async_discovered_device,
{"address": TARGET_DEVICE_ADDRESS},
bluetooth.BluetoothScanningMode.PASSIVE
)
log.info("Bluetooth discovery callback registered successfully.")
awaitasyncio.sleep(10) # Scan for 10 seconds# Store cancel_callback in a global var if you need to unregister later# global my_cancel_callback# my_cancel_callback = cancel_callbackexceptExceptionase:
log.error(f"Failed to register Bluetooth callback: {e}")
log.info("ble_scan ended")
How do I make the above work? _async_discovered_device never gets called back
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
How do I make the above work?
_async_discovered_devicenever gets called backBeta Was this translation helpful? Give feedback.
All reactions