krahabb / meross_lan

Home Assistant integration for Meross devices
MIT License
422 stars 47 forks source link

Adapt to changed mqtt.async_publish in Home Assistant 2021.12 #106

Closed emontnemery closed 2 years ago

emontnemery commented 2 years ago

mqtt.async_publish is a couroutine in HA core 2021.12: home-assistant/core#58441

This can be solved as suggested here: https://github.com/blakeblackshear/frigate-hass-integration/pull/166

If mqtt.async_publish is called from a non-coroutine, use hass.async_create_task if it's not practical to convert the caller to a coroutine:

hass.async_create_task(mqtt.async_publish(hass, topic, payload))
krahabb commented 2 years ago

Hello @emontnemery , thank you very much for hinting at this. While fixing my code I've also found the '@bind_hass' decorator was removed to both the 'sync' and 'async' publish functions while it reamains on other signatures like async_subscribe for instance. Is this just a temporary inconsistency ? or maybe there's something bigger behind my overall weak knowledge of the core api? I'm asking since I would like to implement a stable (the most) update to my code Thank you

emontnemery commented 2 years ago

We don't promote the @bind_hass decorator anymore as calling a function via the hass objects prevents most linters from doing their job. The change to mqtt.async_publish was anyway a breaking change so I removed the @bind_hass from the changed functions.