Skip to content

Commit

Permalink
Add handling for RoborockTooFrequentCodeRequests for roborock integ…
Browse files Browse the repository at this point in the history
…ration (#123759)

* Add handling for RoborockTooFrequentCodeRequests

* Add tests for coverage
  • Loading branch information
yuxincs committed Aug 20, 2024
1 parent d8cbb35 commit 097162e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions homeassistant/components/roborock/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
RoborockException,
RoborockInvalidCode,
RoborockInvalidEmail,
RoborockTooFrequentCodeRequests,
RoborockUrlException,
)
from roborock.web_api import RoborockApiClient
Expand Down Expand Up @@ -83,6 +84,8 @@ async def _request_code(self) -> dict:
errors["base"] = "unknown_url"
except RoborockInvalidEmail:
errors["base"] = "invalid_email_format"
except RoborockTooFrequentCodeRequests:
errors["base"] = "too_frequent_code_requests"
except RoborockException:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown_roborock"
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/roborock/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"invalid_code": "The code you entered was incorrect, please check it and try again.",
"invalid_email": "There is no account associated with the email you entered, please try again.",
"invalid_email_format": "There is an issue with the formatting of your email - please try again.",
"too_frequent_code_requests": "You have attempted to request too many codes. Try again later.",
"unknown_roborock": "There was an unknown roborock exception - please check your logs.",
"unknown_url": "There was an issue determining the correct url for your roborock account - please check your logs.",
"unknown": "[%key:common::config_flow::error::unknown%]"
Expand Down
2 changes: 2 additions & 0 deletions tests/components/roborock/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from unittest.mock import patch

import pytest
from roborock import RoborockTooFrequentCodeRequests
from roborock.exceptions import (
RoborockAccountDoesNotExist,
RoborockException,
Expand Down Expand Up @@ -71,6 +72,7 @@ async def test_config_flow_success(
(RoborockException(), {"base": "unknown_roborock"}),
(RoborockAccountDoesNotExist(), {"base": "invalid_email"}),
(RoborockInvalidEmail(), {"base": "invalid_email_format"}),
(RoborockTooFrequentCodeRequests(), {"base": "too_frequent_code_requests"}),
(RoborockUrlException(), {"base": "unknown_url"}),
(Exception(), {"base": "unknown"}),
],
Expand Down

0 comments on commit 097162e

Please sign in to comment.