Reolink improve webhook URL error message (#96088)

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
starkillerOG 2023-07-24 22:01:45 +02:00 committed by GitHub
parent 410b343ae0
commit 8a58675be2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 2 deletions

View File

@ -17,7 +17,7 @@ from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.device_registry import format_mac
from .const import CONF_PROTOCOL, CONF_USE_HTTPS, DOMAIN
from .exceptions import ReolinkException, UserNotAdmin
from .exceptions import ReolinkException, ReolinkWebhookException, UserNotAdmin
from .host import ReolinkHost
_LOGGER = logging.getLogger(__name__)
@ -133,6 +133,12 @@ class ReolinkFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
except ApiError as err:
placeholders["error"] = str(err)
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:
placeholders["error"] = str(err)
errors[CONF_HOST] = "cannot_connect"

View File

@ -22,7 +22,8 @@
"cannot_connect": "Failed to connect, check the IP address of the camera",
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"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": {
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",

View File

@ -9,6 +9,7 @@ from homeassistant import config_entries, data_entry_flow
from homeassistant.components import dhcp
from homeassistant.components.reolink import const
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.core import HomeAssistant
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["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(
"test_error", "test", 1
)