Open pierrei opened 6 months ago
Looking closer at the code it seems like the built in pinging does a connect, so I suppose this is as expected. The delay in commands I see after running HA for > 1 day should be because of something else I guess then 🤔
I added some more logging and ran that version to see what's going on in more detail. It looks like this is the problem. When a bluetooth device is discovered it triggers a ping, which seems to discover the device again and the loop starts. I'm not sure why this ping on discovery is needed or what benefit it brings. Would it be possible to remove this ping or only do a ping if the device hasn't been seen before?
An example from the custom logging I added in plejd_site.py
for both _ping
and _discovered
:
2024-05-11 21:41:13.746 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S38 D93A LE
2024-05-11 21:41:13.746 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device, creating ping task
2024-05-11 21:41:13.747 INFO (MainThread) [custom_components.plejd.plejd_site] Ping
2024-05-11 21:41:13.804 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S19 A86D LE
2024-05-11 21:41:13.804 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device, creating ping task
2024-05-11 21:41:13.805 INFO (MainThread) [custom_components.plejd.plejd_site] Ping
2024-05-11 21:41:13.892 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S38 D93A LE
2024-05-11 21:41:13.893 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device, creating ping task
2024-05-11 21:41:13.893 INFO (MainThread) [custom_components.plejd.plejd_site] Ping
2024-05-11 21:41:14.428 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S38 D93A LE
2024-05-11 21:41:14.429 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device, creating ping task
2024-05-11 21:41:14.429 INFO (MainThread) [custom_components.plejd.plejd_site] Ping
2024-05-11 21:41:14.488 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S38 D93A LE
2024-05-11 21:41:14.489 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device, creating ping task
2024-05-11 21:41:14.489 INFO (MainThread) [custom_components.plejd.plejd_site] Ping
2024-05-11 21:41:15.986 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S19 A86D LE
2024-05-11 21:41:15.986 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device, creating ping task
2024-05-11 21:41:15.986 INFO (MainThread) [custom_components.plejd.plejd_site] Ping
2024-05-11 21:41:16.226 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S19 A86D LE
2024-05-11 21:41:16.226 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device, creating ping task
2024-05-11 21:41:16.226 INFO (MainThread) [custom_components.plejd.plejd_site] Ping
I also realized I seem to get calls to _discovered
for other types of Bluetooth devices. I guess the service_uuid
thing is supposed to filter on only the Plejd mesh but seems like it's not working for some reason 🤔
Created two PRs to see if @thomasloven agrees it could fix this issue.
https://github.com/thomasloven/pyplejd/pull/7: To return true
if a added device is new
https://github.com/thomasloven/hass-plejd/pull/70: To use the previous to only send a ping if the device discovered was new
This makes perfect sense to me. I'll merge it as soon as I find the time. Thanks!
I've noticed that after a while running HA with the integration it starts taking time for a change in HA to actually happen with lights/switches. While debugging I saw that the
pyplejd
lib used in this integration was "Trying to connect to mesh" over and over again. Not sure if this is the cause of the slowness issue or not but it looks suspicious. Is it supposed to attempt to reconnect over and over again? It seems to happen less often just after a restart but when it's been running for a day this fills the logs completely.Excerpt from the logs when debug logging is on: