From 7b896779cc722e8744707ab5a6816602ef1a439e Mon Sep 17 00:00:00 2001 From: Alberto Geniola Date: Sun, 5 Jun 2022 09:05:05 +0200 Subject: [PATCH] Fix bad mqtt domain name passed by http device discovery --- .version | 2 +- meross_iot/manager.py | 6 +++++- meross_iot/utilities/network.py | 9 +++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 meross_iot/utilities/network.py diff --git a/.version b/.version index 6bb94658..560d5464 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.4.4.5 \ No newline at end of file +0.4.4.6 \ No newline at end of file diff --git a/meross_iot/manager.py b/meross_iot/manager.py index eddc044e..879c66b4 100644 --- a/meross_iot/manager.py +++ b/meross_iot/manager.py @@ -43,6 +43,7 @@ device_uuid_from_push_notification, build_device_request_topic, ) +from meross_iot.utilities.network import extract_domain logging.basicConfig( format="%(levelname)s:%(message)s", level=logging.INFO, stream=sys.stdout @@ -157,6 +158,7 @@ async def _async_get_create_mqtt_client(self, domain: str, port: int) -> mqtt.Cl conn_evt = self._mqtt_connected_and_subscribed.get(dict_key) # type: asyncio.Event if conn_evt is None: conn_evt = asyncio.Event() + _LOGGER.debug("MQTT client connecting to %s:%d", domain, port) client.connect(host=domain, port=port, keepalive=30) self._mqtt_connected_and_subscribed[dict_key] = conn_evt # Start the client looper @@ -410,13 +412,15 @@ async def _async_enroll_new_http_dev( device = None abilities = None if device_info.online_status == OnlineStatus.ONLINE: + mqtt_domain = extract_domain(device_info.domain) + try: res_abilities = await self.async_execute_cmd( destination_device_uuid=device_info.uuid, method="GET", namespace=Namespace.SYSTEM_ABILITY, payload={}, - mqtt_hostname=device_info.domain, + mqtt_hostname=mqtt_domain, mqtt_port=DEFAULT_MQTT_PORT ) abilities = res_abilities.get("ability") diff --git a/meross_iot/utilities/network.py b/meross_iot/utilities/network.py new file mode 100644 index 00000000..78bdae44 --- /dev/null +++ b/meross_iot/utilities/network.py @@ -0,0 +1,9 @@ +import logging + + +_LOGGER = logging.getLogger(__name__) + + +def extract_domain(address: str) -> str: + tokens = address.split(":") + return tokens[0]