How to fix "custom integration 'brematic' calls async_write_ha_state"

Hi there,

I use a fairly old (and small) integration, which worked well so far. But with the current beta 2024.5, I can’t use it anymore and get this error:

Detected that custom integration 'brematic' calls async_write_ha_state from a thread at custom_components/brematic/switch.py, line 242: self.async_write_ha_state().

These are the lines, that are causing this issue: hass-brematic/custom_components/brematic/switch.py at 4e76898b638528d5058d02f986aafcb39189a012 · tefinger/hass-brematic · GitHub

I’m quite certain that the author will not respond to this quickly (if ever). Is it easy to fix this issue manually? Would really appreciate some help.

Thanks!

I think it’s just updating the async_write_ha_state() to schedule_update_ha_state() since it’s not in an async function.

Yes that’s it! Thanks you very much. Worked without issues

It’s likely not a thread safe application, which recently (2024.4.x) is causing HA to crash after the full conversion to python 3.12.
You should check it with this process: Discord.
It is in the general channel of the HA Discord and will tell you if this is integration is writing unsafe thread writes.
If you can’t get to it let me know.

There is also an official fix for this now: Fix async issue by TheZoker · Pull Request #15 · tefinger/hass-brematic · GitHub