Improve error reporting when switchbot auth fails (#85244)
* Improve error reporting when switchbot auth fails related issue #85243 * bump * coveragepull/85277/head
parent
59d6f827c3
commit
fa4c250001
|
@ -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,
|
||||
},
|
||||
)
|
||||
|
||||
|
|
|
@ -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": [
|
||||
|
|
|
@ -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%]",
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
"unknown": "Unexpected error"
|
||||
},
|
||||
"error": {
|
||||
"auth_failed": "Authentication failed",
|
||||
"auth_failed": "Authentication failed: {error_detail}",
|
||||
"encryption_key_invalid": "Key ID or Encryption key is invalid"
|
||||
},
|
||||
"flow_title": "{name} ({address})",
|
||||
|
@ -47,18 +47,7 @@
|
|||
"data": {
|
||||
"address": "Device address"
|
||||
}
|
||||
},
|
||||
"lock_key": {
|
||||
"description": "The {name} device requires encryption key, details on how to obtain it can be found in the documentation.",
|
||||
"data": {
|
||||
"key_id": "Key ID",
|
||||
"encryption_key": "Encryption key"
|
||||
}
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
"key_id_invalid": "Key ID or Encryption key is invalid",
|
||||
"encryption_key_invalid": "Key ID or Encryption key is invalid"
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
|
@ -70,4 +59,4 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue