Betree / magicblue

💡 Unofficial Python API to control Magic Blue bulbs over Bluetooth
MIT License
100 stars 23 forks source link

v8 bulbs can't connect sometimes #30

Closed mouth4war closed 7 years ago

mouth4war commented 7 years ago

The fix is to have addr type set to random if version is 8.

Commit has been tested locally and it works.

Betree commented 7 years ago

Thanks for this, I don't have any v8 to test myself but I'm glad to hear you solved it !

Could you make a pull request ?

mouth4war commented 7 years ago

Already have (staging #29 )

mouth4war commented 7 years ago

Background:

I'm able to connect to all the bulbs with gatttool but not magicblueshell (exceptions are thrown for 2 bulbs of the 5 - ERROR:magicblue.magicblueshell:Unexpected error with command "connect...). The other 3 connect using magicblueshell just fine (INFO:magicblue.magicblueshell:Connected).

The exception seems to be coming from blue.py using addr type Public instead of Random. bluepy.btle.BTLEException Failed to connect to peripheral XXXXXX, addr type: public

The function def _figure_addr_type needs to have a check for v8 and setting addr type to random. I have made this change locally and now I'm able to connect to all 5 bulbs.

mouth4war commented 7 years ago

FYI I got it to work from homeassistant too. Had to modify the file manually in the deps folder.

Betree commented 7 years ago

@mouth4war Thank you, I just merged your changes and deployed a new version 0.4.3 on pypi