diff --git a/homeassistant/components/mysensors/gateway.py b/homeassistant/components/mysensors/gateway.py index 3bdd884079e..177dbbe4dc9 100644 --- a/homeassistant/components/mysensors/gateway.py +++ b/homeassistant/components/mysensors/gateway.py @@ -17,6 +17,8 @@ from homeassistant.components.mqtt import ( DOMAIN as MQTT_DOMAIN, ReceiveMessage as MQTTReceiveMessage, ReceivePayloadType, + async_publish, + async_subscribe, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_DEVICE, EVENT_HOMEASSISTANT_STOP @@ -171,13 +173,10 @@ async def _get_gateway( # Naive check that doesn't consider config entry state. if MQTT_DOMAIN not in hass.config.components: return None - mqtt = hass.components.mqtt def pub_callback(topic: str, payload: str, qos: int, retain: bool) -> None: """Call MQTT publish function.""" - hass.async_create_task( - mqtt.async_publish(hass, topic, payload, qos, retain) - ) + hass.async_create_task(async_publish(hass, topic, payload, qos, retain)) def sub_callback( topic: str, sub_cb: Callable[[str, ReceivePayloadType, int], None], qos: int @@ -189,7 +188,7 @@ async def _get_gateway( """Call callback.""" sub_cb(msg.topic, msg.payload, msg.qos) - hass.async_create_task(mqtt.async_subscribe(topic, internal_callback, qos)) + hass.async_create_task(async_subscribe(hass, topic, internal_callback, qos)) gateway = mysensors.AsyncMQTTGateway( pub_callback,