Skip to content

Commit 50abf3a

Browse files
Update to version 0.1.8
Fixing release function and adding add_status_listener function
1 parent ce06118 commit 50abf3a

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "python-roborock"
3-
version = "0.1.7"
3+
version = "0.1.8"
44
description = ""
55
authors = ["humbertogontijo <humbertogontijo@users.noreply.github.com>"]
66
license = "GPL-3.0-only"

roborock/api.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
import time
1717
from asyncio import Lock
1818
from asyncio.exceptions import TimeoutError, CancelledError
19-
from typing import Any
19+
from typing import Any, Callable
2020
from urllib.parse import urlparse
2121

2222
import aiohttp
2323
import paho.mqtt.client as mqtt
2424
from Crypto.Cipher import AES
2525
from Crypto.Util.Padding import pad, unpad
26+
from roborock.code_mappings import STATE_CODE_TO_STATUS
2627

2728
from roborock.containers import (
2829
UserData,
@@ -126,6 +127,7 @@ def __init__(self, user_data: UserData, device_map: dict[str, RoborockDeviceInfo
126127
self._mutex = Lock()
127128
self._last_device_msg_in = mqtt.time_func()
128129
self._last_disconnection = mqtt.time_func()
130+
self._status_listeners: list[Callable[[str, str], None]] = []
129131

130132
def __del__(self) -> None:
131133
self.sync_disconnect()
@@ -196,7 +198,10 @@ async def on_message(self, _client, _, msg, __=None) -> None:
196198
f"id={request_id} Ignoring response: {data_point_response}"
197199
)
198200
elif data_point_number == "121":
199-
_LOGGER.debug(f"Remote control {data_point}")
201+
status = STATE_CODE_TO_STATUS.get(data_point)
202+
_LOGGER.debug(f"Status updated to {status}")
203+
for listener in self._status_listeners:
204+
listener(device_id, status)
200205
else:
201206
_LOGGER.debug(
202207
f"Unknown data point number received {data_point_number} with {data_point}"
@@ -222,8 +227,7 @@ async def on_message(self, _client, _, msg, __=None) -> None:
222227
@run_in_executor()
223228
async def on_disconnect(self, _client: mqtt.Client, _, rc, __=None) -> None:
224229
try:
225-
async with self._mutex:
226-
self._last_disconnection = mqtt.time_func()
230+
self._last_disconnection = mqtt.time_func()
227231
message = f"Roborock mqtt client disconnected (rc: {rc})"
228232
_LOGGER.warning(message)
229233
connection_queue = self._waiting_queue.get(1)
@@ -248,6 +252,9 @@ async def _async_check_keepalive(self) -> None:
248252
if now - self._last_disconnection > self._keepalive ** 2 and now - self._last_device_msg_in > self._keepalive:
249253
self._ping_t = self._last_device_msg_in
250254

255+
def add_status_listener(self, callback: Callable[[str, str], None]):
256+
self._status_listeners.append(callback)
257+
251258
def _check_keepalive(self) -> None:
252259
self._async_check_keepalive()
253260
super()._check_keepalive()

0 commit comments

Comments
 (0)