Add handling for RoborockTooFrequentCodeRequests for roborock integration (#123759)

* Add handling for RoborockTooFrequentCodeRequests

* Add tests for coverage
This commit is contained in:
Yuxin Wang 2024-08-20 00:09:01 -04:00 committed by GitHub
parent d8cbb3540f
commit 097162eceb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 0 deletions

View File

@ -12,6 +12,7 @@ from roborock.exceptions import (
RoborockException,
RoborockInvalidCode,
RoborockInvalidEmail,
RoborockTooFrequentCodeRequests,
RoborockUrlException,
)
from roborock.web_api import RoborockApiClient
@ -83,6 +84,8 @@ class RoborockFlowHandler(ConfigFlow, domain=DOMAIN):
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"

View File

@ -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%]"

View File

@ -4,6 +4,7 @@ from copy import deepcopy
from unittest.mock import patch
import pytest
from roborock import RoborockTooFrequentCodeRequests
from roborock.exceptions import (
RoborockAccountDoesNotExist,
RoborockException,
@ -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"}),
],