Improve error reporting when switchbot auth fails (#85244)

* Improve error reporting when switchbot auth fails

related issue #85243

* bump

* coverage
This commit is contained in:
J. Nick Koston 2023-01-05 10:29:13 -10:00 committed by GitHub
parent 4a48f0d659
commit 28ad27a3b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 13 additions and 16 deletions

View file

@ -166,6 +166,7 @@ class SwitchbotConfigFlow(ConfigFlow, domain=DOMAIN):
"""Handle the SwitchBot API auth step."""
errors = {}
assert self._discovered_adv is not None
description_placeholders = {}
if user_input is not None:
try:
key_details = await self.hass.async_add_executor_job(
@ -176,8 +177,10 @@ class SwitchbotConfigFlow(ConfigFlow, domain=DOMAIN):
)
except SwitchbotAccountConnectionError as ex:
raise AbortFlow("cannot_connect") from ex
except SwitchbotAuthenticationError:
except SwitchbotAuthenticationError as ex:
_LOGGER.debug("Authentication failed: %s", ex, exc_info=True)
errors = {"base": "auth_failed"}
description_placeholders = {"error_detail": str(ex)}
else:
return await self.async_step_lock_key(key_details)
@ -195,6 +198,7 @@ class SwitchbotConfigFlow(ConfigFlow, domain=DOMAIN):
),
description_placeholders={
"name": name_from_discovery(self._discovered_adv),
**description_placeholders,
},
)

View file

@ -2,7 +2,7 @@
"domain": "switchbot",
"name": "SwitchBot",
"documentation": "https://www.home-assistant.io/integrations/switchbot",
"requirements": ["PySwitchbot==0.36.1"],
"requirements": ["PySwitchbot==0.36.2"],
"config_flow": true,
"dependencies": ["bluetooth"],
"codeowners": [

View file

@ -40,7 +40,7 @@
},
"error": {
"encryption_key_invalid": "Key ID or Encryption key is invalid",
"auth_failed": "Authentication failed"
"auth_failed": "Authentication failed: {error_detail}"
},
"abort": {
"already_configured_device": "[%key:common::config_flow::abort::already_configured_device%]",

View file

@ -8,9 +8,8 @@
"unknown": "Unexpected error"
},
"error": {
"auth_failed": "Authentication failed",
"encryption_key_invalid": "Key ID or Encryption key is invalid",
"key_id_invalid": "Key ID or Encryption key is invalid"
"auth_failed": "Authentication failed: {error_detail}",
"encryption_key_invalid": "Key ID or Encryption key is invalid"
},
"flow_title": "{name} ({address})",
"step": {
@ -31,13 +30,6 @@
"lock_key": "Enter lock encryption key manually"
}
},
"lock_chose_method": {
"description": "Choose configuration method, details can be found in the documentation.",
"menu_options": {
"lock_auth": "SwitchBot app login and password",
"lock_key": "Lock encryption key"
}
},
"lock_key": {
"data": {
"encryption_key": "Encryption key",

View file

@ -40,7 +40,7 @@ PyRMVtransport==0.3.3
PySocks==1.7.1
# homeassistant.components.switchbot
PySwitchbot==0.36.1
PySwitchbot==0.36.2
# homeassistant.components.transport_nsw
PyTransportNSW==0.1.1

View file

@ -36,7 +36,7 @@ PyRMVtransport==0.3.3
PySocks==1.7.1
# homeassistant.components.switchbot
PySwitchbot==0.36.1
PySwitchbot==0.36.2
# homeassistant.components.transport_nsw
PyTransportNSW==0.1.1

View file

@ -481,7 +481,7 @@ async def test_user_setup_wolock_auth(hass):
with patch(
"homeassistant.components.switchbot.config_flow.SwitchbotLock.retrieve_encryption_key",
side_effect=SwitchbotAuthenticationError,
side_effect=SwitchbotAuthenticationError("error from api"),
):
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
@ -494,6 +494,7 @@ async def test_user_setup_wolock_auth(hass):
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "lock_auth"
assert result["errors"] == {"base": "auth_failed"}
assert "error from api" in result["description_placeholders"]["error_detail"]
with patch_async_setup_entry() as mock_setup_entry, patch(
"homeassistant.components.switchbot.config_flow.SwitchbotLock.verify_encryption_key",