1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Fix HomeWizard is not catching RequestError (#73719)

* Fix RequestError was not catched

* Add test for RequestError
This commit is contained in:
Duco Sebel
2022-06-20 10:30:57 +02:00
committed by GitHub
parent 006ea441ad
commit db5e94c93b
3 changed files with 38 additions and 3 deletions

View File

@@ -2,7 +2,7 @@
import logging
from unittest.mock import patch
from homewizard_energy.errors import DisabledError, UnsupportedError
from homewizard_energy.errors import DisabledError, RequestError, UnsupportedError
from homeassistant import config_entries
from homeassistant.components import zeroconf
@@ -333,3 +333,31 @@ async def test_check_detects_invalid_api(hass, aioclient_mock):
assert result["type"] == RESULT_TYPE_ABORT
assert result["reason"] == "unsupported_api_version"
async def test_check_requesterror(hass, aioclient_mock):
"""Test check detecting device endpoint failed fetching data due to a requesterror."""
def mock_initialize():
raise RequestError
device = get_mock_device()
device.device.side_effect = mock_initialize
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == "form"
assert result["step_id"] == "user"
with patch(
"homeassistant.components.homewizard.config_flow.HomeWizardEnergy",
return_value=device,
):
result = await hass.config_entries.flow.async_configure(
result["flow_id"], {CONF_IP_ADDRESS: "2.2.2.2"}
)
assert result["type"] == RESULT_TYPE_ABORT
assert result["reason"] == "unknown_error"