Raise error when unsupported (old) Bond firmware is detected (#38650)

This commit is contained in:
Eugene Prystupa 2020-08-07 22:22:13 -04:00 committed by GitHub
parent 4cceb4ad0a
commit 50cd6be18d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 2 deletions

View file

@ -39,7 +39,11 @@ async def _validate_input(data: Dict[str, Any]) -> str:
raise InputValidationError("unknown") raise InputValidationError("unknown")
# Return unique ID from the hub to be stored in the config entry. # Return unique ID from the hub to be stored in the config entry.
return version["bondid"] bond_id = version.get("bondid")
if not bond_id:
raise InputValidationError("old_firmware")
return bond_id
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):

View file

@ -18,6 +18,7 @@
"error": { "error": {
"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%]",
"old_firmware": "Unsupported old firmware on the Bond device - please upgrade before continuing",
"unknown": "[%key:common::config_flow::error::unknown%]" "unknown": "[%key:common::config_flow::error::unknown%]"
}, },
"abort": { "abort": {

View file

@ -6,6 +6,7 @@
"error": { "error": {
"cannot_connect": "Failed to connect", "cannot_connect": "Failed to connect",
"invalid_auth": "Invalid authentication", "invalid_auth": "Invalid authentication",
"old_firmware": "Unsupported old firmware on the Bond device - please upgrade before continuing",
"unknown": "Unexpected error" "unknown": "Unexpected error"
}, },
"flow_title": "Bond: {bond_id} ({host})", "flow_title": "Bond: {bond_id} ({host})",
@ -24,4 +25,4 @@
} }
} }
} }
} }

View file

@ -79,6 +79,24 @@ async def test_user_form_cannot_connect(hass: core.HomeAssistant):
assert result2["errors"] == {"base": "cannot_connect"} assert result2["errors"] == {"base": "cannot_connect"}
async def test_user_form_old_firmware(hass: core.HomeAssistant):
"""Test we handle unsupported old firmware."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
with patch_bond_version(
return_value={"no_bond_id": "present"}
), patch_bond_device_ids():
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_HOST: "some host", CONF_ACCESS_TOKEN: "test-token"},
)
assert result2["type"] == "form"
assert result2["errors"] == {"base": "old_firmware"}
async def test_user_form_unexpected_client_error(hass: core.HomeAssistant): async def test_user_form_unexpected_client_error(hass: core.HomeAssistant):
"""Test we handle unexpected client error gracefully.""" """Test we handle unexpected client error gracefully."""
await _help_test_form_unexpected_error( await _help_test_form_unexpected_error(