Skip to content

Commit 74c1b5f

Browse files
authored
feat: add some logging for the web api (#377)
1 parent 1070aea commit 74c1b5f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

roborock/web_api.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@ async def _get_base_url(self) -> str:
6868
raise RoborockUrlException("get url by email returned None")
6969
response_code = response.get("code")
7070
if response_code != 200:
71+
_LOGGER.info("Get base url failed for %s with the following context: %s", self._username, response)
7172
if response_code == 2003:
7273
raise RoborockInvalidEmail("Your email was incorrectly formatted.")
7374
elif response_code == 1001:
7475
raise RoborockMissingParameters(
75-
"You are missing parameters for this request, are you sure you " "entered your username?"
76+
"You are missing parameters for this request, are you sure you entered your username?"
7677
)
7778
elif response_code == 9002:
7879
raise RoborockTooManyRequest("Please temporarily disable making requests and try again later.")
@@ -214,6 +215,7 @@ async def request_code(self) -> None:
214215
raise RoborockException("Failed to get a response from send email code")
215216
response_code = code_response.get("code")
216217
if response_code != 200:
218+
_LOGGER.info("Request code failed for %s with the following context: %s", self._username, code_response)
217219
if response_code == 2008:
218220
raise RoborockAccountDoesNotExist("Account does not exist - check your login and try again.")
219221
elif response_code == 9002:
@@ -243,6 +245,7 @@ async def pass_login(self, password: str) -> UserData:
243245
if login_response is None:
244246
raise RoborockException("Login response is none")
245247
if login_response.get("code") != 200:
248+
_LOGGER.info("Login failed for %s with the following context: %s", self._username, login_response)
246249
raise RoborockException(f"{login_response.get('msg')} - response code: {login_response.get('code')}")
247250
user_data = login_response.get("data")
248251
if not isinstance(user_data, dict):
@@ -282,6 +285,7 @@ async def code_login(self, code: int | str) -> UserData:
282285
raise RoborockException("Login request response is None")
283286
response_code = login_response.get("code")
284287
if response_code != 200:
288+
_LOGGER.info("Login failed for %s with the following context: %s", self._username, login_response)
285289
if response_code == 2018:
286290
raise RoborockInvalidCode("Invalid code - check your code and try again.")
287291
if response_code == 3009:
@@ -308,6 +312,7 @@ async def _get_home_id(self, user_data: UserData):
308312
if home_id_response is None:
309313
raise RoborockException("home_id_response is None")
310314
if home_id_response.get("code") != 200:
315+
_LOGGER.info("Get Home Id failed with the following context: %s", home_id_response)
311316
if home_id_response.get("code") == 2010:
312317
raise RoborockInvalidCredentials(
313318
f"Invalid credentials ({home_id_response.get('msg')}) - check your login and try again."

0 commit comments

Comments
 (0)