mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Reolink improve webhook URL error message (#96088)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
410b343ae0
commit
8a58675be2
@ -17,7 +17,7 @@ from homeassistant.helpers import config_validation as cv
|
|||||||
from homeassistant.helpers.device_registry import format_mac
|
from homeassistant.helpers.device_registry import format_mac
|
||||||
|
|
||||||
from .const import CONF_PROTOCOL, CONF_USE_HTTPS, DOMAIN
|
from .const import CONF_PROTOCOL, CONF_USE_HTTPS, DOMAIN
|
||||||
from .exceptions import ReolinkException, UserNotAdmin
|
from .exceptions import ReolinkException, ReolinkWebhookException, UserNotAdmin
|
||||||
from .host import ReolinkHost
|
from .host import ReolinkHost
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -133,6 +133,12 @@ class ReolinkFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
except ApiError as err:
|
except ApiError as err:
|
||||||
placeholders["error"] = str(err)
|
placeholders["error"] = str(err)
|
||||||
errors[CONF_HOST] = "api_error"
|
errors[CONF_HOST] = "api_error"
|
||||||
|
except ReolinkWebhookException as err:
|
||||||
|
placeholders["error"] = str(err)
|
||||||
|
placeholders[
|
||||||
|
"more_info"
|
||||||
|
] = "https://www.home-assistant.io/more-info/no-url-available/#configuring-the-instance-url"
|
||||||
|
errors["base"] = "webhook_exception"
|
||||||
except (ReolinkError, ReolinkException) as err:
|
except (ReolinkError, ReolinkException) as err:
|
||||||
placeholders["error"] = str(err)
|
placeholders["error"] = str(err)
|
||||||
errors[CONF_HOST] = "cannot_connect"
|
errors[CONF_HOST] = "cannot_connect"
|
||||||
|
@ -22,7 +22,8 @@
|
|||||||
"cannot_connect": "Failed to connect, check the IP address of the camera",
|
"cannot_connect": "Failed to connect, check the IP address of the camera",
|
||||||
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
|
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
|
||||||
"not_admin": "User needs to be admin, user ''{username}'' has authorisation level ''{userlevel}''",
|
"not_admin": "User needs to be admin, user ''{username}'' has authorisation level ''{userlevel}''",
|
||||||
"unknown": "[%key:common::config_flow::error::unknown%]"
|
"unknown": "[%key:common::config_flow::error::unknown%]",
|
||||||
|
"webhook_exception": "Home Assistant URL is not available, go to Settings > System > Network > Home Assistant URL and correct the URLs, see {more_info}"
|
||||||
},
|
},
|
||||||
"abort": {
|
"abort": {
|
||||||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
|
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
|
||||||
|
@ -9,6 +9,7 @@ from homeassistant import config_entries, data_entry_flow
|
|||||||
from homeassistant.components import dhcp
|
from homeassistant.components import dhcp
|
||||||
from homeassistant.components.reolink import const
|
from homeassistant.components.reolink import const
|
||||||
from homeassistant.components.reolink.config_flow import DEFAULT_PROTOCOL
|
from homeassistant.components.reolink.config_flow import DEFAULT_PROTOCOL
|
||||||
|
from homeassistant.components.reolink.exceptions import ReolinkWebhookException
|
||||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import format_mac
|
from homeassistant.helpers.device_registry import format_mac
|
||||||
@ -109,6 +110,20 @@ async def test_config_flow_errors(
|
|||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "user"
|
||||||
assert result["errors"] == {CONF_HOST: "cannot_connect"}
|
assert result["errors"] == {CONF_HOST: "cannot_connect"}
|
||||||
|
|
||||||
|
reolink_connect.get_host_data.side_effect = ReolinkWebhookException("Test error")
|
||||||
|
result = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
{
|
||||||
|
CONF_USERNAME: TEST_USERNAME,
|
||||||
|
CONF_PASSWORD: TEST_PASSWORD,
|
||||||
|
CONF_HOST: TEST_HOST,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["type"] is data_entry_flow.FlowResultType.FORM
|
||||||
|
assert result["step_id"] == "user"
|
||||||
|
assert result["errors"] == {"base": "webhook_exception"}
|
||||||
|
|
||||||
reolink_connect.get_host_data.side_effect = json.JSONDecodeError(
|
reolink_connect.get_host_data.side_effect = json.JSONDecodeError(
|
||||||
"test_error", "test", 1
|
"test_error", "test", 1
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user