Skip to content

Commit

Permalink
fix: #498 Support for new Xiaomi Robot Vacuum X20+
Browse files Browse the repository at this point in the history
  • Loading branch information
Yiğit Topcu committed Jun 11, 2024
1 parent 8c2d39c commit 86b830c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions custom_components/dreame_vacuum/dreame/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,19 +796,27 @@ def get_file(self, url: str, retry_count: int = 4) -> Any:

def get_file_url(self, object_name: str = "") -> Any:
api_response = self._api_call(f'home/getfileurl{("_v3" if self._v3 else "")}', {"obj_name": object_name})
_LOGGER.debug("Get file url result: %s", api_response)
_LOGGER.debug("Get file url result: %s = %s", object_name, api_response)
if api_response is None or "result" not in api_response or "url" not in api_response["result"]:
if api_response and api_response.get("code") == -8 and self._v3:
_LOGGER.info("get_file_url fallback to V2")
self._v3 = False
return self.get_file_url(object_name)
return None

return api_response["result"]["url"]

def get_interim_file_url(self, object_name: str = "") -> str:
_LOGGER.debug("Get interim file url: %s", object_name)
api_response = self._api_call(
f'v2/home/get_interim_file_url{("_pro" if self._v3 else "")}',
{"obj_name": object_name},
)
_LOGGER.debug("Get interim file url result: %s = %s", object_name, api_response)
if api_response is None or not api_response.get("result") or "url" not in api_response["result"]:
if api_response and api_response.get("code") == -8 and self._v3:
_LOGGER.info("get_interim_file_url fallback to V2")
self._v3 = False
return self.get_interim_file_url(object_name)
return None

return api_response["result"]["url"]
Expand Down

0 comments on commit 86b830c

Please sign in to comment.