Vallox config flow follow-up fixes (#63032)
* Vallox config flow follow-up fixes * Fix logging * Get documentation URL from manifest * Feedback fixes
This commit is contained in:
parent
77ffd7b066
commit
0a95b2c591
4 changed files with 35 additions and 17 deletions
|
@ -13,6 +13,7 @@ from homeassistant.const import CONF_HOST, CONF_NAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResult
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
|
from homeassistant.loader import async_get_integration
|
||||||
from homeassistant.util.network import is_ip_address
|
from homeassistant.util.network import is_ip_address
|
||||||
|
|
||||||
from .const import DEFAULT_NAME, DOMAIN
|
from .const import DEFAULT_NAME, DOMAIN
|
||||||
|
@ -59,10 +60,10 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
try:
|
try:
|
||||||
await validate_host(self.hass, host)
|
await validate_host(self.hass, host)
|
||||||
except InvalidHost:
|
except InvalidHost:
|
||||||
_LOGGER.exception("An invalid host is configured for Vallox")
|
_LOGGER.error("An invalid host is configured for Vallox: %s", host)
|
||||||
reason = "invalid_host"
|
reason = "invalid_host"
|
||||||
except VALLOX_CONNECTION_EXCEPTIONS:
|
except VALLOX_CONNECTION_EXCEPTIONS:
|
||||||
_LOGGER.exception("Cannot connect to Vallox")
|
_LOGGER.error("Cannot connect to Vallox host %s", host)
|
||||||
reason = "cannot_connect"
|
reason = "cannot_connect"
|
||||||
except Exception: # pylint: disable=broad-except
|
except Exception: # pylint: disable=broad-except
|
||||||
_LOGGER.exception("Unexpected exception")
|
_LOGGER.exception("Unexpected exception")
|
||||||
|
@ -82,9 +83,15 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
"""Handle the initial step."""
|
"""Handle the initial step."""
|
||||||
if user_input is None or user_input[CONF_HOST] is None:
|
integration = await async_get_integration(self.hass, DOMAIN)
|
||||||
|
|
||||||
|
if user_input is None:
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="user", data_schema=STEP_USER_DATA_SCHEMA
|
step_id="user",
|
||||||
|
description_placeholders={
|
||||||
|
"integration_docs_url": integration.documentation
|
||||||
|
},
|
||||||
|
data_schema=STEP_USER_DATA_SCHEMA,
|
||||||
)
|
)
|
||||||
|
|
||||||
errors = {}
|
errors = {}
|
||||||
|
@ -112,7 +119,12 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
)
|
)
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
|
step_id="user",
|
||||||
|
description_placeholders={
|
||||||
|
"integration_docs_url": integration.documentation
|
||||||
|
},
|
||||||
|
data_schema=STEP_USER_DATA_SCHEMA,
|
||||||
|
errors=errors,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,19 +3,22 @@
|
||||||
"step": {
|
"step": {
|
||||||
"user": {
|
"user": {
|
||||||
"title": "Vallox",
|
"title": "Vallox",
|
||||||
"description": "Set up the Vallox integration. If you have problems with configuration go to https://www.home-assistant.io/integrations/vallox.",
|
"description": "Set up the Vallox integration. If you have problems with configuration go to {integration_docs_url}.",
|
||||||
"data": {
|
"data": {
|
||||||
"host": "[%key:common::config_flow::data::host%]",
|
"host": "[%key:common::config_flow::data::host%]"
|
||||||
"name": "[%key:common::config_flow::data::name%]"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"abort": {
|
"abort": {
|
||||||
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]"
|
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]",
|
||||||
|
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
||||||
|
"invalid_host": "[%key:common::config_flow::error::invalid_host%]",
|
||||||
|
"unknown": "[%key:common::config_flow::error::unknown%]"
|
||||||
},
|
},
|
||||||
"error": {
|
"error": {
|
||||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
||||||
"invalid_host": "[%key:common::config_flow::error::invalid_host%]"
|
"invalid_host": "[%key:common::config_flow::error::invalid_host%]",
|
||||||
|
"unknown": "[%key:common::config_flow::error::unknown%]"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,22 @@
|
||||||
{
|
{
|
||||||
"config": {
|
"config": {
|
||||||
"abort": {
|
"abort": {
|
||||||
"already_configured": "Service is already configured"
|
"already_configured": "Service is already configured",
|
||||||
|
"cannot_connect": "Failed to connect",
|
||||||
|
"invalid_host": "Invalid hostname or IP address",
|
||||||
|
"unknown": "Unknown error"
|
||||||
},
|
},
|
||||||
"error": {
|
"error": {
|
||||||
"cannot_connect": "Failed to connect",
|
"cannot_connect": "Failed to connect",
|
||||||
"invalid_host": "Invalid hostname or IP address"
|
"invalid_host": "Invalid hostname or IP address",
|
||||||
|
"unknown": "Unknown error"
|
||||||
},
|
},
|
||||||
"step": {
|
"step": {
|
||||||
"user": {
|
"user": {
|
||||||
"data": {
|
"data": {
|
||||||
"host": "Host",
|
"host": "Host"
|
||||||
"name": "Name"
|
|
||||||
},
|
},
|
||||||
"description": "Set up the Vallox integration. If you have problems with configuration go to https://www.home-assistant.io/integrations/vallox.",
|
"description": "Set up the Vallox integration. If you have problems with configuration go to {integration_docs_url}.",
|
||||||
"title": "Vallox"
|
"title": "Vallox"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -241,7 +241,7 @@ async def test_import_already_configured(hass: HomeAssistant) -> None:
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
|
|
||||||
async def test_import_cannot_connect_OSError(hass: HomeAssistant) -> None:
|
async def test_import_cannot_connect_os_error(hass: HomeAssistant) -> None:
|
||||||
"""Test that cannot connect error is handled."""
|
"""Test that cannot connect error is handled."""
|
||||||
name = "Vallox 90 MV"
|
name = "Vallox 90 MV"
|
||||||
|
|
||||||
|
@ -260,7 +260,7 @@ async def test_import_cannot_connect_OSError(hass: HomeAssistant) -> None:
|
||||||
assert result["reason"] == "cannot_connect"
|
assert result["reason"] == "cannot_connect"
|
||||||
|
|
||||||
|
|
||||||
async def test_import_cannot_connect_ValloxApiException(hass: HomeAssistant) -> None:
|
async def test_import_cannot_connect_vallox_api_exception(hass: HomeAssistant) -> None:
|
||||||
"""Test that cannot connect error is handled."""
|
"""Test that cannot connect error is handled."""
|
||||||
name = "Vallox 90 MV"
|
name = "Vallox 90 MV"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue