hbldh / bleak

A cross platform Bluetooth Low Energy Client for Python using asyncio
MIT License
1.56k stars 275 forks source link

NoneType error when calling client.pair() on Android #1531

Open skywodd opened 1 month ago

skywodd commented 1 month ago

Description

The p4android backend seem to have a bug in the BleakClientP4Android.pair() method. When called, the function is working but always crash with the exception TypeError: object NoneType can't be used in 'await' expression.

This is caused by the line await receiver.stop(). It look like the BroadcastReceiver.stop() method is just a plain def, not a async def : https://github.com/kivy/python-for-android/blob/develop/pythonforandroid/recipes/android/src/android/broadcast.py#L67

What I Did

Run the kivy example with an added await client.pair() after the client connection.

Logs

03-28 19:38:56.988 22522 18640 I python  :  Traceback (most recent call last):
03-28 19:38:56.989 22522 18640 I python  :    File "/REDACTED/.buildozer/android/app/main.py", line 327, in _handle_sensor
03-28 19:38:56.989 22522 18640 I python  :    File "/REDACTED/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/androidkivytest/arm64-v8a/bleak/__init__.py", line 640, in pair
03-28 19:38:56.989 22522 18640 I python  :    File "/REDACTED/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/androidkivytest/arm64-v8a/bleak/backends/p4android/client.py", line 213, in pair
03-28 19:38:56.990 22522 18640 I python  :  TypeError: object NoneType can't be used in 'await' expression
moisesms0 commented 3 weeks ago

Did you fix it? i have the same error in almost the same situation