Skip to content

Commit

Permalink
Remove error and test that can't be triggered yet
Browse files Browse the repository at this point in the history
  • Loading branch information
davet2001 committed Dec 30, 2024
1 parent eb7fafb commit 32ca8e5
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 72 deletions.
15 changes: 0 additions & 15 deletions homeassistant/components/generic/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
RTSP_TRANSPORTS,
SOURCE_TIMEOUT,
Stream,
StreamOpenClientError,
create_stream,
)
from homeassistant.config_entries import (
Expand Down Expand Up @@ -291,8 +290,6 @@ async def async_test_and_preview_stream(
f"{DOMAIN}.test_stream",
)
hls_provider = stream.add_provider(HLS_PROVIDER)
except StreamOpenClientError as err:
raise InvalidStreamException("unknown_with_details", str(err)) from err
except PermissionError as err:
raise InvalidStreamException("stream_not_permitted") from err
except OSError as err:
Expand Down Expand Up @@ -346,7 +343,6 @@ async def async_step_user(
) -> ConfigFlowResult:
"""Handle the start of the config flow."""
errors = {}
description_placeholders = {}
hass = self.hass
if user_input:
# Secondary validation because serialised vol can't seem to handle this complexity:
Expand All @@ -362,8 +358,6 @@ async def async_step_user(
)
except InvalidStreamException as err:
errors[CONF_STREAM_SOURCE] = str(err)
if err.details:
errors["error_details"] = err.details
self.preview_stream = None
if not errors:
user_input[CONF_CONTENT_TYPE] = still_format
Expand All @@ -382,16 +376,13 @@ async def async_step_user(
# temporary preview for user to check the image
self.preview_cam = user_input
return await self.async_step_user_confirm()
if "error_details" in errors:
description_placeholders["error"] = errors.pop("error_details")
elif self.user_input:
user_input = self.user_input
else:
user_input = DEFAULT_DATA.copy()
return self.async_show_form(
step_id="user",
data_schema=build_schema(user_input),
description_placeholders=description_placeholders,
errors=errors,
)

Expand Down Expand Up @@ -440,7 +431,6 @@ async def async_step_init(
) -> ConfigFlowResult:
"""Manage Generic IP Camera options."""
errors: dict[str, str] = {}
description_placeholders = {}
hass = self.hass

if user_input:
Expand All @@ -457,8 +447,6 @@ async def async_step_init(
)
except InvalidStreamException as err:
errors[CONF_STREAM_SOURCE] = str(err)
if err.details:
errors["error_details"] = err.details
self.preview_stream = None
if not errors:
user_input[CONF_CONTENT_TYPE] = still_format
Expand All @@ -480,8 +468,6 @@ async def async_step_init(
# temporary preview for user to check the image
self.preview_cam = data
return await self.async_step_user_confirm()
if "error_details" in errors:
description_placeholders["error"] = errors.pop("error_details")
elif self.user_input:
user_input = self.user_input
return self.async_show_form(
Expand All @@ -491,7 +477,6 @@ async def async_step_init(
True,
self.show_advanced_options,
),
description_placeholders=description_placeholders,
errors=errors,
)

Expand Down
57 changes: 0 additions & 57 deletions tests/components/generic/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from homeassistant.components.stream import (
CONF_RTSP_TRANSPORT,
CONF_USE_WALLCLOCK_AS_TIMESTAMPS,
StreamOpenClientError,
)
from homeassistant.config_entries import ConfigEntryState, ConfigFlowResult
from homeassistant.const import (
Expand Down Expand Up @@ -661,25 +660,6 @@ async def test_form_stream_other_error(hass: HomeAssistant, user_flow) -> None:
await hass.async_block_till_done()


@respx.mock
@pytest.mark.usefixtures("fakeimg_png")
async def test_form_stream_worker_error(
hass: HomeAssistant, user_flow: ConfigFlowResult
) -> None:
"""Test we handle a StreamOpenClientError and pass the message through."""
with patch(
"homeassistant.components.generic.config_flow.create_stream",
side_effect=StreamOpenClientError("Some message", 999),
):
result2 = await hass.config_entries.flow.async_configure(
user_flow["flow_id"],
TESTDATA,
)
assert result2["type"] is FlowResultType.FORM
assert result2["errors"] == {"stream_source": "unknown_with_details"}
assert result2["description_placeholders"] == {"error": "Some message"}


@respx.mock
async def test_form_stream_permission_error(
hass: HomeAssistant, fakeimgbytes_png: bytes, user_flow: ConfigFlowResult
Expand Down Expand Up @@ -866,43 +846,6 @@ async def test_options_template_error(
assert result7["errors"] == {"stream_source": "malformed_url"}


@respx.mock
@pytest.mark.usefixtures("fakeimg_png")
async def test_options_stream_other_error(
hass: HomeAssistant, fakeimgbytes_png: bytes, user_flow: ConfigFlowResult
) -> None:
"""Test we handle a StreamOpenClientError and pass the message through."""
respx.get("http://127.0.0.1/testurl/1").respond(stream=fakeimgbytes_png)
respx.get("http://127.0.0.1/testurl/2").respond(stream=fakeimgbytes_png)

mock_entry = MockConfigEntry(
title="Test Camera",
domain=DOMAIN,
data={},
options=TESTDATA,
)

mock_entry.add_to_hass(hass)
await hass.config_entries.async_setup(mock_entry.entry_id)
await hass.async_block_till_done()

result = await hass.config_entries.options.async_init(mock_entry.entry_id)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "init"

with patch(
"homeassistant.components.generic.config_flow.create_stream",
side_effect=StreamOpenClientError("A problem", "with detail"),
):
result2 = await hass.config_entries.options.async_configure(
result["flow_id"],
TESTDATA,
)
assert result2["type"] is FlowResultType.FORM
assert result2["errors"] == {"stream_source": "unknown_with_details"}
assert result2["description_placeholders"] == {"error": "A problem"}


async def test_slug(hass: HomeAssistant, caplog: pytest.LogCaptureFixture) -> None:
"""Test that the slug function generates an error in case of invalid template.
Expand Down

0 comments on commit 32ca8e5

Please sign in to comment.