kevincar / bless

Cross-platform Bluetooth Low Energy Server Python Library
MIT License
111 stars 30 forks source link

How to use method "self.BlessServer.is_connected()" #73

Closed WouterJD closed 2 years ago

WouterJD commented 2 years ago

The problem How to use method BlessServer.is_connected()

Reproduction The following statement is not allowed (assignment in wait): await b = self.BlessServer.is_connected()

Expected behavior b = len(self.BlessServer._subscribed_clients) > 0

Suggestion Perhaps the method should not be async, but I'm not very familiar with asynchronous coding.

kevincar commented 2 years ago

I would recommend perusing the the async documentation. There are some short, simple examples of implementation.

Perhaps you meant to use: b = await self.BlessServer.is_connected()

I should also acknowledge that the is_connected function is currently a misnomer. Not all backends (Windows/macOS/DBus) check for connectivity in the same way. The way I've implemented bless to check for connectivity is to determine whether a peripheral device has subscribed to any subscribable characteristics. As a result is_connected() currently only returns True when the client has subscribed to an available characteristic that is broadcast by bless

WouterJD commented 2 years ago

Thanks, sorry for not finding this in docu. The IsConnected() works as "desired" ; when the client aborts, it returns False

kevincar commented 2 years ago

No problem