MQTT Device Discovery Issue (Bug?)

Hi all. I’m the maintainer of the ring-mqtt script and the Ring MQTT HA community add-on, which provides support for Ring Alarm and Smart Lighting, Modes settings, etc) and I’ve recently been working to add support for the HA device registry as part of the MQTT discovery process. Overall this was pretty simple, just adding some device data as part of the discovery process.

However, I’m having one issue I can’t seem to overcome. There can be quite a lot of devices to add to the device registry during the initial run, however, what happens is that, if I have, for example, 20 devices, only maybe 3-5 of them will actually register, and some of them will register only partially. Even if I resend the discovery data, the same devices just continue this way. If I restart HA the devices will still be there and then I can send another 3-5. Eventually, after all devices are registered, everything works OK.

I’ve found that I can somewhat work around this problem by putting a delay of say, 1 second, between each discovery message (I tried 500ms and that helped some but not 100%). This seems quite hackish and causes an issue since, in some cases, environments have dozens or I’ve even seen cases of 100+ sensors.

I remember having some similarish issues with MQTT device discovery with entities back in the day, but that’s been working solidly with this script for a while. Nothing has changed at all with how I issue the MQTT discovery messages other than including the additional device info. Previously the script just created entities without devices and always worked a treat (technically it still works, the entities are created fully, just not the devices).

I can certainly open an issue but I wondered first if I was just doing something incorrectly or if there were ideas to try, although the overall process seems super straightforward.