|
6 | 6 | from abc import ABC |
7 | 7 | from asyncio import Lock |
8 | 8 | from typing import Any |
9 | | -from urllib.parse import urlparse |
10 | 9 |
|
11 | 10 | import paho.mqtt.client as mqtt |
12 | 11 |
|
13 | 12 | from .api import KEEPALIVE, RoborockClient |
14 | 13 | from .containers import DeviceData, UserData |
15 | 14 | from .exceptions import RoborockException, VacuumError |
16 | | -from .protocol import MessageParser, md5hex |
| 15 | +from .protocol import MessageParser, create_mqtt_params |
17 | 16 | from .roborock_future import RoborockFuture |
18 | 17 |
|
19 | 18 | _LOGGER = logging.getLogger(__name__) |
@@ -53,25 +52,20 @@ def __init__(self, user_data: UserData, device_info: DeviceData) -> None: |
53 | 52 | if rriot is None: |
54 | 53 | raise RoborockException("Got no rriot data from user_data") |
55 | 54 | RoborockClient.__init__(self, device_info) |
| 55 | + mqtt_params = create_mqtt_params(rriot) |
56 | 56 | self._mqtt_user = rriot.u |
57 | | - self._hashed_user = md5hex(self._mqtt_user + ":" + rriot.k)[2:10] |
58 | | - url = urlparse(rriot.r.m) |
59 | | - if not isinstance(url.hostname, str): |
60 | | - raise RoborockException("Url parsing returned an invalid hostname") |
61 | | - self._mqtt_host = str(url.hostname) |
62 | | - self._mqtt_port = url.port |
63 | | - self._mqtt_ssl = url.scheme == "ssl" |
| 57 | + self._hashed_user = mqtt_params.username |
| 58 | + self._mqtt_host = mqtt_params.host |
| 59 | + self._mqtt_port = mqtt_params.port |
64 | 60 |
|
65 | 61 | self._mqtt_client = _Mqtt() |
66 | 62 | self._mqtt_client.on_connect = self._mqtt_on_connect |
67 | 63 | self._mqtt_client.on_message = self._mqtt_on_message |
68 | 64 | self._mqtt_client.on_disconnect = self._mqtt_on_disconnect |
69 | | - if self._mqtt_ssl: |
| 65 | + if mqtt_params.tls: |
70 | 66 | self._mqtt_client.tls_set() |
71 | 67 |
|
72 | | - self._mqtt_password = rriot.s |
73 | | - self._hashed_password = md5hex(self._mqtt_password + ":" + rriot.k)[16:] |
74 | | - self._mqtt_client.username_pw_set(self._hashed_user, self._hashed_password) |
| 68 | + self._mqtt_client.username_pw_set(mqtt_params.username, mqtt_params.password) |
75 | 69 | self._waiting_queue: dict[int, RoborockFuture] = {} |
76 | 70 | self._mutex = Lock() |
77 | 71 |
|
|
0 commit comments