undera / pylgbst

Python library for LEGO® PoweredUp devices
MIT License
554 stars 121 forks source link

Incompatibility with Bleak 0.8.0+ #89

Closed antoinechauveau closed 3 years ago

antoinechauveau commented 3 years ago

Bleak made a breaking change to the constructor of class BleakClient in release 0.8.0. See https://github.com/hbldh/bleak/pull/224 for details.

Since this project still uses the old interface, connection to MoveHub fails with:

780     INFO    comms-bleak     Discovering devices... Press green button on Hub
10847   INFO    comms   Found LEGO Move Hub at 00:16:53:A3:BE:3E
10848   INFO    comms-bleak     Device matched: 00:16:53:A3:BE:3E: LEGO Move Hub
Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Users\Antoine\AppData\Local\Programs\Python\Python38\lib\asyncio\runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "C:\Users\Antoine\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 608, in run_until_complete
    return future.result()
  File "C:\Users\Antoine\AppData\Local\Programs\Python\Python38\lib\site-packages\pylgbst\comms\cbleak.py", line 60, in _bleak_thread
    await bleak.connect(self.hub_mac, self.hub_name)
  File "C:\Users\Antoine\AppData\Local\Programs\Python\Python38\lib\site-packages\pylgbst\comms\cbleak.py", line 156, in connect
    self._client = BleakClient(self._device.address, self.loop)
TypeError: __init__() takes 2 positional arguments but 3 were given

Removing the extraneous parameter "self.loop" is sufficient for successful connection and running demo.py on the latest Bleak 0.11.0, but I don't have enough experience of this code to tell whether that's the correct or complete fix.

This was already reported in comment https://github.com/undera/pylgbst/issues/76#issuecomment-727526972 to a closed issue, but I think that it deserves better visibility.

undera commented 3 years ago

IMO we should migrate onto bleak 0.8+. If somebody can provide a PR implementing this - would be great.