diff --git a/homeassistant/components/mqtt/client.py b/homeassistant/components/mqtt/client.py index 021ecf1cc36..9a344e13023 100644 --- a/homeassistant/components/mqtt/client.py +++ b/homeassistant/components/mqtt/client.py @@ -41,6 +41,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.typing import ConfigType from homeassistant.loader import bind_hass from homeassistant.util import dt as dt_util +from homeassistant.util.async_ import create_eager_task from homeassistant.util.logging import catch_log_exception from .const import ( @@ -352,7 +353,7 @@ class EnsureJobAfterCooldown: return self._async_cancel_timer() - self._task = asyncio.create_task(self._async_job()) + self._task = create_eager_task(self._async_job()) self._task.add_done_callback(self._async_task_done) @callback diff --git a/tests/components/mqtt/test_discovery.py b/tests/components/mqtt/test_discovery.py index 24891895fad..a00af080bf1 100644 --- a/tests/components/mqtt/test_discovery.py +++ b/tests/components/mqtt/test_discovery.py @@ -1487,6 +1487,7 @@ async def test_mqtt_integration_discovery_subscribe_unsubscribe( await async_start(hass, "homeassistant", entry) await hass.async_block_till_done() await hass.async_block_till_done() + await hass.async_block_till_done() assert ("comp/discovery/#", 0) in help_all_subscribe_calls(mqtt_client_mock) assert not mqtt_client_mock.unsubscribe.called @@ -1537,6 +1538,7 @@ async def test_mqtt_discovery_unsubscribe_once( await async_start(hass, "homeassistant", entry) await hass.async_block_till_done() await hass.async_block_till_done() + await hass.async_block_till_done() assert ("comp/discovery/#", 0) in help_all_subscribe_calls(mqtt_client_mock) assert not mqtt_client_mock.unsubscribe.called