Improve Config Flow and handle TooManyAttemptsBannedException in Overkiz (#68868)

pull/68875/head
Mick Vleeshouwer 2022-03-29 19:19:57 -07:00 committed by GitHub
parent 9a150c2234
commit 365ea59b64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 11 additions and 4 deletions

View File

@ -9,6 +9,7 @@ from pyoverkiz.const import SUPPORTED_SERVERS
from pyoverkiz.exceptions import (
BadCredentialsException,
MaintenanceException,
TooManyAttemptsBannedException,
TooManyRequestsException,
)
from pyoverkiz.models import obfuscate_id
@ -51,7 +52,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
async with OverkizClient(
username=username, password=password, server=server, session=session
) as client:
await client.login()
await client.login(register_event_listener=False)
# Set first gateway id as unique id
if gateways := await client.get_gateways():
@ -78,6 +79,8 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
errors["base"] = "cannot_connect"
except MaintenanceException:
errors["base"] = "server_in_maintenance"
except TooManyAttemptsBannedException:
errors["base"] = "too_many_attempts"
except Exception as exception: # pylint: disable=broad-except
errors["base"] = "unknown"
LOGGER.exception(exception)

View File

@ -4,7 +4,7 @@
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/overkiz",
"requirements": [
"pyoverkiz==1.3.12"
"pyoverkiz==1.3.13"
],
"zeroconf": [
{

View File

@ -16,6 +16,7 @@
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"server_in_maintenance": "Server is down for maintenance",
"too_many_attempts": "Too many attempts with an invalid token, temporarily banned",
"too_many_requests": "Too many requests, try again later",
"unknown": "[%key:common::config_flow::error::unknown%]"
},

View File

@ -9,6 +9,7 @@
"cannot_connect": "Failed to connect",
"invalid_auth": "Invalid authentication",
"server_in_maintenance": "Server is down for maintenance",
"too_many_attempts": "Too many attempts with an invalid token, temporarily banned",
"too_many_requests": "Too many requests, try again later",
"unknown": "Unexpected error"
},

View File

@ -1700,7 +1700,7 @@ pyotgw==1.1b1
pyotp==2.6.0
# homeassistant.components.overkiz
pyoverkiz==1.3.12
pyoverkiz==1.3.13
# homeassistant.components.openweathermap
pyowm==3.2.0

View File

@ -1135,7 +1135,7 @@ pyotgw==1.1b1
pyotp==2.6.0
# homeassistant.components.overkiz
pyoverkiz==1.3.12
pyoverkiz==1.3.13
# homeassistant.components.openweathermap
pyowm==3.2.0

View File

@ -7,6 +7,7 @@ from aiohttp import ClientError
from pyoverkiz.exceptions import (
BadCredentialsException,
MaintenanceException,
TooManyAttemptsBannedException,
TooManyRequestsException,
)
import pytest
@ -86,6 +87,7 @@ async def test_form(hass: HomeAssistant) -> None:
(TimeoutError, "cannot_connect"),
(ClientError, "cannot_connect"),
(MaintenanceException, "server_in_maintenance"),
(TooManyAttemptsBannedException, "too_many_attempts"),
(Exception, "unknown"),
],
)