mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 06:47:09 +00:00
Add error message to options flow if connection fails for nut integration (#46972)
This commit is contained in:
parent
5d7b53603f
commit
8e58c3aa7b
@ -6,6 +6,7 @@ import voluptuous as vol
|
||||
from homeassistant import config_entries, core, exceptions
|
||||
from homeassistant.const import (
|
||||
CONF_ALIAS,
|
||||
CONF_BASE,
|
||||
CONF_HOST,
|
||||
CONF_PASSWORD,
|
||||
CONF_PORT,
|
||||
@ -211,10 +212,10 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
try:
|
||||
info = await validate_input(self.hass, config)
|
||||
except CannotConnect:
|
||||
errors["base"] = "cannot_connect"
|
||||
errors[CONF_BASE] = "cannot_connect"
|
||||
except Exception: # pylint: disable=broad-except
|
||||
_LOGGER.exception("Unexpected exception")
|
||||
errors["base"] = "unknown"
|
||||
errors[CONF_BASE] = "unknown"
|
||||
return info, errors
|
||||
|
||||
@staticmethod
|
||||
@ -241,7 +242,17 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
|
||||
CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
|
||||
)
|
||||
|
||||
errors = {}
|
||||
try:
|
||||
info = await validate_input(self.hass, self.config_entry.data)
|
||||
except CannotConnect:
|
||||
errors[CONF_BASE] = "cannot_connect"
|
||||
except Exception: # pylint: disable=broad-except
|
||||
_LOGGER.exception("Unexpected exception")
|
||||
errors[CONF_BASE] = "unknown"
|
||||
|
||||
if errors:
|
||||
return self.async_show_form(step_id="abort", errors=errors)
|
||||
|
||||
base_schema = _resource_schema_base(info["available_resources"], resources)
|
||||
base_schema[
|
||||
@ -249,10 +260,13 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
|
||||
] = cv.positive_int
|
||||
|
||||
return self.async_show_form(
|
||||
step_id="init",
|
||||
data_schema=vol.Schema(base_schema),
|
||||
step_id="init", data_schema=vol.Schema(base_schema), errors=errors
|
||||
)
|
||||
|
||||
async def async_step_abort(self, user_input=None):
|
||||
"""Abort options flow."""
|
||||
return self.async_create_entry(title="", data=self.config_entry.options)
|
||||
|
||||
|
||||
class CannotConnect(exceptions.HomeAssistantError):
|
||||
"""Error to indicate we cannot connect."""
|
||||
|
@ -41,6 +41,10 @@
|
||||
"scan_interval": "Scan Interval (seconds)"
|
||||
}
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
||||
"unknown": "[%key:common::config_flow::error::unknown%]"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,10 @@
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"error": {
|
||||
"cannot_connect": "Failed to connect",
|
||||
"unknown": "Unexpected error"
|
||||
},
|
||||
"step": {
|
||||
"init": {
|
||||
"data": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user