Skip to content

Commit

Permalink
Fix bad mqtt domain name passed by http device discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
albertogeniola committed Jun 5, 2022
1 parent f18b81f commit 7b89677
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.4.5
0.4.4.6
6 changes: 5 additions & 1 deletion meross_iot/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
9 changes: 9 additions & 0 deletions meross_iot/utilities/network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import logging


_LOGGER = logging.getLogger(__name__)


def extract_domain(address: str) -> str:
tokens = address.split(":")
return tokens[0]

0 comments on commit 7b89677

Please sign in to comment.