akasma74 / Hass-Custom-Alarm

It is a fork of "Yet another take on a home assistant custom alarm" that will exist until its author is back to our Earth
80 stars 31 forks source link

Adapt to changed mqtt.async_publish in HA core 2021.12 #135

Open emontnemery opened 2 years ago

emontnemery commented 2 years ago

mqtt.async_publish is a couroutine in HA core 2021.12: https://github.com/home-assistant/core/pull/58441

In addition to the change in this PR, either a hacs.json is needed, with minimum HA version set to 2021.12 or something like this would work to keep compatibility with old versions of Home Assistant Core:

hass.async_add_job(async_publish, hass, topic, payload)
akasma74 commented 2 years ago

Hi @emontnemery,

Thanks for your PR and sorry for the long delay. When I apply your PR to my system (HA 0.111.1), it works BUT I get this error in logs:

TypeError: object NoneType can't be used in 'await' expression

It works without errors if I replace the async_publish with

self._hass.async_add_job(self._mqtt.async_publish, self._hass, self._state_topic, state_name, self._qos, True)

but I don't quite get why the await bit causes errors and how to keep compatibility with old versions of HA - could you elaborate? I don't use HACS.