Skip to content

Commit

Permalink
Code review: Remove schema double check
Browse files Browse the repository at this point in the history
  • Loading branch information
davet2001 committed Jul 31, 2024
1 parent 86802a1 commit ee52452
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions homeassistant/components/generic/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,8 @@ async def ws_start_preview(
_LOGGER.debug("Generating websocket handler for generic camera preview")

Check warning on line 572 in homeassistant/components/generic/config_flow.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/generic/config_flow.py#L571-L572

Added lines #L571 - L572 were not covered by tests

flow = hass.config_entries.flow.async_get(msg["flow_id"])
schema = build_schema({})
user_input = deepcopy(flow["context"]["preview_cam"])
del user_input[CONF_CONTENT_TYPE] # The schema doesn't like this generated field.

Check warning on line 576 in homeassistant/components/generic/config_flow.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/generic/config_flow.py#L574-L576

Added lines #L574 - L576 were not covered by tests
validated = schema(user_input)

# Create an EntityPlatform, needed for name translations
platform = await async_prepare_setup_platform(hass, {}, CAMERA_DOMAIN, DOMAIN)
Expand All @@ -590,14 +588,14 @@ async def ws_start_preview(
)
await entity_platform.async_load_translations()

Check warning on line 589 in homeassistant/components/generic/config_flow.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/generic/config_flow.py#L589

Added line #L589 was not covered by tests

validated[CONF_LIMIT_REFETCH_TO_URL_CHANGE] = False
user_input[CONF_LIMIT_REFETCH_TO_URL_CHANGE] = False

Check warning on line 591 in homeassistant/components/generic/config_flow.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/generic/config_flow.py#L591

Added line #L591 was not covered by tests

ext_still_url = validated.get(CONF_STILL_IMAGE_URL)
ext_stream_url = validated.get(CONF_STREAM_SOURCE)
ext_still_url = user_input.get(CONF_STILL_IMAGE_URL)
ext_stream_url = user_input.get(CONF_STREAM_SOURCE)

Check warning on line 594 in homeassistant/components/generic/config_flow.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/generic/config_flow.py#L593-L594

Added lines #L593 - L594 were not covered by tests

if ext_still_url:
errors, still_format = await async_test_still(hass, validated)
validated[CONF_CONTENT_TYPE] = still_format
errors, still_format = await async_test_still(hass, user_input)
user_input[CONF_CONTENT_TYPE] = still_format
register_preview(hass)

Check warning on line 599 in homeassistant/components/generic/config_flow.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/generic/config_flow.py#L596-L599

Added lines #L596 - L599 were not covered by tests

ha_still_url = f"/api/generic/preview_flow_image/{msg['flow_id']}?t={datetime.now().isoformat()}"
Expand All @@ -606,18 +604,18 @@ async def ws_start_preview(
# If user didn't specify a still image URL,
# The automatically generated still image that stream generates
# is always jpeg
validated[CONF_CONTENT_TYPE] = "image/jpeg"
user_input[CONF_CONTENT_TYPE] = "image/jpeg"
ha_still_url = None

Check warning on line 608 in homeassistant/components/generic/config_flow.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/generic/config_flow.py#L607-L608

Added lines #L607 - L608 were not covered by tests

ha_stream_url = None
if ext_stream_url:
errors = errors | await async_test_stream(hass, validated)
errors = errors | await async_test_stream(hass, user_input)
if not errors:
preview_entity = GenericCamera(

Check warning on line 614 in homeassistant/components/generic/config_flow.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/generic/config_flow.py#L610-L614

Added lines #L610 - L614 were not covered by tests
hass, validated, msg["flow_id"] + "stream_preview", "PreviewStream"
hass, user_input, msg["flow_id"] + "stream_preview", "PreviewStream"
)
preview_entity.platform = entity_platform
ha_stream_url = await register_stream_preview(hass, validated)
ha_stream_url = await register_stream_preview(hass, user_input)

Check warning on line 618 in homeassistant/components/generic/config_flow.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/generic/config_flow.py#L617-L618

Added lines #L617 - L618 were not covered by tests

connection.send_result(msg["id"])
connection.send_message(

Check warning on line 621 in homeassistant/components/generic/config_flow.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/generic/config_flow.py#L620-L621

Added lines #L620 - L621 were not covered by tests
Expand Down

0 comments on commit ee52452

Please sign in to comment.