JorgePe / pyb00st

Python for LEGO BOOST
MIT License
143 stars 21 forks source link

is_connected() assumes that the adapter is always pygatt.GATTToolBackend #7

Open vinkolar opened 6 years ago

vinkolar commented 6 years ago

This is while using movehub on macOS using BGAPI. I understand that you only support linux for now. Please feel free to close this issue if it is not relevant

https://github.com/JorgePe/pyb00st/blob/bf15272481d0541461923820f98983d9f10ebcc9/pyb00st/movehub.py#L143

Only pygatt.GATTToolBackend has the variable _con. However, the adapter can also be of the instance pygatt.BGAPIBackend. Using BGAPIBackend does not have _con variable. Hence the code breaks at this point

Current bad fix I introduced in is_connected() to get other stuff running:

    def is_connected(self):
        # not sure about this - GATToolBacked returns True if the
        # process is running so if we power off the Move Hub it
        # keeps returning True 
        if (type(self.adapter) == pygatt.backends.bgapi.bgapi.BGAPIBackend):
            return True
        else:
            return self.adapter._con.isalive()

Tested on python3 with pygatt-3.2.0 on macOS