Improve Vodafone Station setup dialog messages (#100937)

This commit is contained in:
Simone Chemelli 2023-09-26 20:16:50 +02:00 committed by GitHub
parent 4d7e3d2b0f
commit e18ff03244
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 2 deletions

View File

@ -68,10 +68,14 @@ class VodafoneStationConfigFlow(ConfigFlow, domain=DOMAIN):
try: try:
info = await validate_input(self.hass, user_input) info = await validate_input(self.hass, user_input)
except aiovodafone_exceptions.AlreadyLogged:
errors["base"] = "already_logged"
except aiovodafone_exceptions.CannotConnect: except aiovodafone_exceptions.CannotConnect:
errors["base"] = "cannot_connect" errors["base"] = "cannot_connect"
except aiovodafone_exceptions.CannotAuthenticate: except aiovodafone_exceptions.CannotAuthenticate:
errors["base"] = "invalid_auth" errors["base"] = "invalid_auth"
except aiovodafone_exceptions.ModelNotSupported:
errors["base"] = "model_not_supported"
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
_LOGGER.exception("Unexpected exception") _LOGGER.exception("Unexpected exception")
errors["base"] = "unknown" errors["base"] = "unknown"
@ -99,6 +103,8 @@ class VodafoneStationConfigFlow(ConfigFlow, domain=DOMAIN):
if user_input is not None: if user_input is not None:
try: try:
await validate_input(self.hass, {**self.entry.data, **user_input}) await validate_input(self.hass, {**self.entry.data, **user_input})
except aiovodafone_exceptions.AlreadyLogged:
errors["base"] = "already_logged"
except aiovodafone_exceptions.CannotConnect: except aiovodafone_exceptions.CannotConnect:
errors["base"] = "cannot_connect" errors["base"] = "cannot_connect"
except aiovodafone_exceptions.CannotAuthenticate: except aiovodafone_exceptions.CannotAuthenticate:

View File

@ -12,21 +12,24 @@
"data": { "data": {
"host": "[%key:common::config_flow::data::host%]", "host": "[%key:common::config_flow::data::host%]",
"username": "[%key:common::config_flow::data::username%]", "username": "[%key:common::config_flow::data::username%]",
"password": "[%key:common::config_flow::data::password%]", "password": "[%key:common::config_flow::data::password%]"
"ssl": "[%key:common::config_flow::data::ssl%]"
} }
} }
}, },
"abort": { "abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]", "already_configured": "[%key:common::config_flow::abort::already_configured_service%]",
"already_logged": "User already logged-in, please try again later.",
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]", "reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]",
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]", "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]", "invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"model_not_supported": "The device model is currently unsupported.",
"unknown": "[%key:common::config_flow::error::unknown%]" "unknown": "[%key:common::config_flow::error::unknown%]"
}, },
"error": { "error": {
"already_logged": "User already logged-in, please try again later.",
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]", "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]", "invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"model_not_supported": "The device model is currently unsupported.",
"unknown": "[%key:common::config_flow::error::unknown%]" "unknown": "[%key:common::config_flow::error::unknown%]"
} }
}, },

View File

@ -52,6 +52,8 @@ async def test_user(hass: HomeAssistant) -> None:
[ [
(aiovodafone_exceptions.CannotConnect, "cannot_connect"), (aiovodafone_exceptions.CannotConnect, "cannot_connect"),
(aiovodafone_exceptions.CannotAuthenticate, "invalid_auth"), (aiovodafone_exceptions.CannotAuthenticate, "invalid_auth"),
(aiovodafone_exceptions.AlreadyLogged, "already_logged"),
(aiovodafone_exceptions.ModelNotSupported, "model_not_supported"),
(ConnectionResetError, "unknown"), (ConnectionResetError, "unknown"),
], ],
) )
@ -152,6 +154,7 @@ async def test_reauth_successful(hass: HomeAssistant) -> None:
[ [
(aiovodafone_exceptions.CannotConnect, "cannot_connect"), (aiovodafone_exceptions.CannotConnect, "cannot_connect"),
(aiovodafone_exceptions.CannotAuthenticate, "invalid_auth"), (aiovodafone_exceptions.CannotAuthenticate, "invalid_auth"),
(aiovodafone_exceptions.AlreadyLogged, "already_logged"),
(ConnectionResetError, "unknown"), (ConnectionResetError, "unknown"),
], ],
) )