Skip to content

Commit

Permalink
fix: add timeout as a variable and set a longer default timeout for c…
Browse files Browse the repository at this point in the history
…loud
  • Loading branch information
Lash-L committed Sep 11, 2023
1 parent 1f7d46c commit c3ce248
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions roborock/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@

_LOGGER = logging.getLogger(__name__)
KEEPALIVE = 60
QUEUE_TIMEOUT = 4
COMMANDS_SECURED = [
RoborockCommand.GET_MAP_V1,
RoborockCommand.GET_MULTI_MAP,
Expand Down Expand Up @@ -166,7 +165,7 @@ async def refresh_value(self):


class RoborockClient:
def __init__(self, endpoint: str, device_info: DeviceData) -> None:
def __init__(self, endpoint: str, device_info: DeviceData, queue_timeout: int = 4) -> None:
self.event_loop = get_running_loop_or_create_one()
self.device_info = device_info
self._endpoint = endpoint
Expand All @@ -186,6 +185,7 @@ def __init__(self, endpoint: str, device_info: DeviceData) -> None:
self.cache: dict[CacheableAttribute, AttributeCache] = cache
self._listeners: list[Callable[[str, CacheableAttribute, RoborockBase], None]] = []
self.is_available: bool = False
self.queue_timeout = queue_timeout

def __del__(self) -> None:
self.release()
Expand Down Expand Up @@ -323,12 +323,12 @@ async def validate_connection(self) -> None:

async def _wait_response(self, request_id: int, queue: RoborockFuture) -> tuple[Any, VacuumError | None]:
try:
(response, err) = await queue.async_get(QUEUE_TIMEOUT)
(response, err) = await queue.async_get(self.queue_timeout)
if response == "unknown_method":
raise UnknownMethodError("Unknown method")
return response, err
except (asyncio.TimeoutError, asyncio.CancelledError):
raise RoborockTimeout(f"id={request_id} Timeout after {QUEUE_TIMEOUT} seconds") from None
raise RoborockTimeout(f"id={request_id} Timeout after {self.queue_timeout} seconds") from None
finally:
self._waiting_queue.pop(request_id, None)

Expand Down
4 changes: 2 additions & 2 deletions roborock/cloud_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ class RoborockMqttClient(RoborockClient, mqtt.Client):
_thread: threading.Thread
_client_id: str

def __init__(self, user_data: UserData, device_info: DeviceData) -> None:
def __init__(self, user_data: UserData, device_info: DeviceData, queue_timeout: int = 10) -> None:
rriot = user_data.rriot
if rriot is None:
raise RoborockException("Got no rriot data from user_data")
endpoint = base64.b64encode(Utils.md5(rriot.k.encode())[8:14]).decode()
RoborockClient.__init__(self, endpoint, device_info)
RoborockClient.__init__(self, endpoint, device_info, queue_timeout)
mqtt.Client.__init__(self, protocol=mqtt.MQTTv5)
self._logger = RoborockLoggerAdapter(device_info.device.name, _LOGGER)
self._mqtt_user = rriot.u
Expand Down
4 changes: 2 additions & 2 deletions roborock/local_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@


class RoborockLocalClient(RoborockClient, asyncio.Protocol):
def __init__(self, device_data: DeviceData):
def __init__(self, device_data: DeviceData, queue_timeout: int = 4):
if device_data.host is None:
raise RoborockException("Host is required")
super().__init__("abc", device_data)
super().__init__("abc", device_data, queue_timeout)
self.host = device_data.host
self._batch_structs: list[RoborockMessage] = []
self._executing = False
Expand Down

0 comments on commit c3ce248

Please sign in to comment.