Skip to content

Commit e26e351

Browse files
authored
feat: raise no account error when bad login (#743)
* feat: raise no account error when bad login * chore: add test
1 parent 07cef03 commit e26e351

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

roborock/web_api.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,10 @@ async def code_login_v4(
359359
raise RoborockInvalidUserAgreement(
360360
"User agreement must be accepted again - or you are attempting to use the Mi Home app account."
361361
)
362+
if response_code == 3039:
363+
raise RoborockAccountDoesNotExist(
364+
"This account does not exist - please ensure that you selected the right region and email."
365+
)
362366
raise RoborockException(f"{login_response.get('msg')} - response code: {response_code}")
363367
user_data = login_response.get("data")
364368
if not isinstance(user_data, dict):

tests/test_web_api.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from aioresponses.compat import normalize_url
77

88
from roborock import HomeData, HomeDataScene, UserData
9+
from roborock.exceptions import RoborockAccountDoesNotExist
910
from roborock.web_api import IotLoginInfo, RoborockApiClient
1011
from tests.mock_data import HOME_DATA_RAW, USER_DATA
1112

@@ -88,6 +89,42 @@ async def test_code_login_v4_flow(mock_rest) -> None:
8889
assert ud == UserData.from_dict(USER_DATA)
8990

9091

92+
async def test_code_login_v4_account_does_not_exist(mock_rest) -> None:
93+
"""Test that response code 3039 raises RoborockAccountDoesNotExist."""
94+
mock_rest.clear()
95+
96+
mock_rest.post(
97+
re.compile(r"https://.*iot\.roborock\.com/api/v1/getUrlByEmail.*"),
98+
status=200,
99+
payload={
100+
"code": 200,
101+
"data": {"country": "US", "countrycode": "1", "url": "https://usiot.roborock.com"},
102+
"msg": "success",
103+
},
104+
)
105+
mock_rest.post(
106+
re.compile(r"https://.*iot\.roborock\.com/api/v4/email/code/send.*"),
107+
status=200,
108+
payload={"code": 200, "data": None, "msg": "success"},
109+
)
110+
mock_rest.post(
111+
re.compile(r"https://.*iot\.roborock\.com/api/v3/key/sign.*"),
112+
status=200,
113+
payload={"code": 200, "data": {"k": "mock_k"}, "msg": "success"},
114+
)
115+
mock_rest.post(
116+
re.compile(r"https://.*iot\.roborock\.com/api/v4/auth/email/login/code.*"),
117+
status=200,
118+
payload={"code": 3039, "data": None, "msg": "account does not exist"},
119+
)
120+
121+
api = RoborockApiClient(username="test_user@gmail.com")
122+
await api.request_code_v4()
123+
with pytest.raises(RoborockAccountDoesNotExist) as exc_info:
124+
await api.code_login_v4(4123, "US", 1)
125+
assert "This account does not exist" in str(exc_info.value)
126+
127+
91128
async def test_url_cycling(mock_rest) -> None:
92129
"""Test that we cycle through the URLs correctly."""
93130
# Clear mock rest so that we can override the patches.

0 commit comments

Comments
 (0)