thomasloven / lovelace-auto-entities

🔹Automatically populate the entities-list of lovelace cards
MIT License
1.27k stars 116 forks source link

Race condition causes unreliable behavior with custom container cards #301

Open mag1024 opened 2 years ago

mag1024 commented 2 years ago

I believe there is a race condition in auto-entities code that causes it to behave unreliably (to occasionally fail to load and just display a blank card) especially with custom container cards, presumably because they are slower to load. This issue is likely the root cause of piitaya/lovelace-mushroom#698 and #286.

It appears that that is a lack on synchronization to wait for the container card to finish loading before we start adding entities to it. Specifically, I have observed that adding a "sleep" (await new Promise(r => setTimeout(r, 200));) before this line appears to work around the problem, although I don't know enough about JS to know what the proper fix is.

mag1024 commented 2 years ago

This comment by @jcwillox (thanks, Josh!) might have some clues as per the real cause.