thomasloven / hass-plejd

šŸ”¹ Plejd BLE integration for Home Assistant
96 stars 9 forks source link

Not pinging when new device is discovered #68

Open pierrei opened 6 months ago

pierrei commented 6 months ago

Related to https://github.com/thomasloven/hass-plejd/issues/66.

It seems that doing a ping when a new device is discovered causes flooding of Bluetooth traffic. Not sure if this happens to everyone but for me I get quite a lot of "discovered" events, even from Bluetooth devices that are not Plejd. Every time this happens it triggers a ping, which in turn discovers more devices.

I added some logging in the _discovered function and this is a sample of what I see in my HA logs:

2024-05-26 08:42:15.040 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S19 A86D LE
2024-05-26 08:42:15.109 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S19 A86D LE
2024-05-26 08:42:17.299 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S19 A86D LE
2024-05-26 08:42:17.360 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S19 A86D LE
2024-05-26 08:42:17.886 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S19 A86D LE
2024-05-26 08:42:17.959 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S19 A86D LE
2024-05-26 08:42:19.340 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S19 A86D LE
2024-05-26 08:42:19.511 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S19 A86D LE
2024-05-26 08:42:19.806 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S19 A86D LE
2024-05-26 08:42:20.116 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S19 A86D LE
2024-05-26 08:42:20.545 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S19 A86D LE
2024-05-26 08:42:20.716 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S19 A86D LE
2024-05-26 08:42:21.326 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S19 A86D LE
2024-05-26 08:42:21.495 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S19 A86D LE
2024-05-26 08:42:23.048 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S19 A86D LE
2024-05-26 08:42:23.133 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S19 A86D LE
2024-05-26 08:42:26.076 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S19 A86D LE
2024-05-26 08:42:26.333 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S19 A86D LE
2024-05-26 08:42:30.667 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S19 A86D LE
2024-05-26 08:42:30.720 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S19 A86D LE
2024-05-26 08:42:32.539 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S19 A86D LE
2024-05-26 08:42:32.629 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S19 A86D LE
2024-05-26 08:42:35.045 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S19 A86D LE
2024-05-26 08:42:35.215 INFO (MainThread) [custom_components.plejd.plejd_site] Discovered device S19 A86D LE

I don't know why the ping was added in the first place, but I've removed it and has been running flawlessly on my HA for weeks now.

thomasloven commented 6 months ago

The ping also polls the mesh for the current state, so in case the discovery was of a device which just joined the network you would get the state from that immediately.

I'll need to think about if this can be removed entirely without performance impact or if there are other solutions - e.g. a rate limit...

pierrei commented 6 months ago

Ah, so that's why! I was guessing it was there for a reason šŸ˜ƒ

One alternative I was thinking was to have manager.add_mesh_device() return a boolean that would be true if the device was actually added and false if it is in the registry already. I guess in this case it would ping only when true - that should also solve it.