From b2a8cf9684807b5b606ac2717ce8811032b0a047 Mon Sep 17 00:00:00 2001 From: Tom Rosenback Date: Thu, 11 Apr 2024 22:45:19 +0300 Subject: [PATCH] Import mqtt from homeasssistant.components instead of using directly through hass.components (#56) Co-authored-by: Tom Rosenback --- custom_components/thermiq_mqtt/heatpump/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/custom_components/thermiq_mqtt/heatpump/__init__.py b/custom_components/thermiq_mqtt/heatpump/__init__.py index 491a237..0d2915b 100644 --- a/custom_components/thermiq_mqtt/heatpump/__init__.py +++ b/custom_components/thermiq_mqtt/heatpump/__init__.py @@ -23,6 +23,7 @@ ATTR_OPTION, ) from homeassistant.core import HomeAssistant +from homeassistant.components import mqtt from ..const import ( @@ -234,7 +235,8 @@ def __init__(self, hass, entry: ConfigEntry): async def setup_mqtt(self): self._hpstate["time_str"] = self._data_topic - self.unsubscribe_callback = await self._hass.components.mqtt.async_subscribe( + self.unsubscribe_callback = await mqtt.async_subscribe( + self._hass, self._data_topic, self.message_received, ) @@ -290,8 +292,8 @@ def update_state(self, command, state_command): _LOGGER.debug("update_state:" + command + " " + state_command) # self._data[state_command] = self._client.command(command) # hass.async_create_task( - # hass.components.mqtt.async_publish( - # conf.cmd_topic, self._data[state_command] + # mqtt.async_publish( + # self._hass, conf.cmd_topic, self._data[state_command] # ) # ) @@ -343,7 +345,7 @@ async def send_mqtt_reg(self, register_id, value, bitmask) -> None: _LOGGER.debug("topic:[%s]", topic) _LOGGER.debug("payload:[%s]", payload) self._hass.async_create_task( - self._hass.components.mqtt.async_publish( + mqtt.async_publish( self._hass, topic, payload, qos=2, retain=False ) )