Replies: 1 comment
-
Starting and stopping a scanner multiple times should be fine. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I just wanted to check: the preferred pattern is to create a new instance every time you need to scan (
BleakScanner
), or connect to a device (BleakClient
).Especially with
BleakClient
this seems important due to inconsistent state inBleakClient
after disconnect as mentioned in #713 (comment) and a few other places.I'm not sure if this is also critical in
BleakScanner
, but most of the examples (such as this one #933 (comment)) use a newBleakScanner
instance every time (theBleakScanner.find_by_*
class methods create a short-livedBleakScanner
instance internally).So is it correct to say, its not really recommended to keep a
BleakScanner
instance and callstart()
,stop()
andstart()
again, etc. as needed? Likewise withBleakClient
it is not recommended to callconnect()
after adisconnect()
?Since bleak is a relatively young project, I wonder if it is a good idea for bleak to enforce the recommended pattern and just raise an exception when
connect()
is called after a previousdisconnect()
on aBleakClient
, orstart()
afterstop()
on aBleakScanner
? It might help with the OOP complexities of inconsistent state in long-lived instances mentioned in #713 and I think elsewhere.Maybe this should have been an issue instead of a discussion post but I just wanted to check I have understood (happy to open an issue for this suggestion if anyone things it is worth it).
Beta Was this translation helpful? Give feedback.
All reactions