From 65ea54927d1a68bc4bd62895fff3c3fb92c9bbd2 Mon Sep 17 00:00:00 2001 From: ZuluWhiskey <35011199+ZuluWhiskey@users.noreply.github.com> Date: Tue, 1 Feb 2022 17:05:50 +0000 Subject: [PATCH] Fix MotionEye config flow (#64360) Co-authored-by: Paulus Schoutsen Co-authored-by: Paulus Schoutsen --- .../components/motioneye/config_flow.py | 20 +++++++++---------- .../components/motioneye/test_config_flow.py | 18 +++++++++++++++++ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/motioneye/config_flow.py b/homeassistant/components/motioneye/config_flow.py index 84a6d0771e6..0361f4562c4 100644 --- a/homeassistant/components/motioneye/config_flow.py +++ b/homeassistant/components/motioneye/config_flow.py @@ -222,17 +222,15 @@ class MotionEyeOptionsFlow(OptionsFlow): if self.show_advanced_options: # The input URL is not validated as being a URL, to allow for the possibility - # the template input won't be a valid URL until after it's rendered. - schema.update( - { - vol.Required( - CONF_STREAM_URL_TEMPLATE, - default=self._config_entry.options.get( - CONF_STREAM_URL_TEMPLATE, - "", - ), - ): str + # the template input won't be a valid URL until after it's rendered + stream_kwargs = {} + if CONF_STREAM_URL_TEMPLATE in self._config_entry.options: + stream_kwargs["description"] = { + "suggested_value": self._config_entry.options[ + CONF_STREAM_URL_TEMPLATE + ] } - ) + + schema[vol.Optional(CONF_STREAM_URL_TEMPLATE, **stream_kwargs)] = str return self.async_show_form(step_id="init", data_schema=vol.Schema(schema)) diff --git a/tests/components/motioneye/test_config_flow.py b/tests/components/motioneye/test_config_flow.py index 57def069d59..9ef0f78874d 100644 --- a/tests/components/motioneye/test_config_flow.py +++ b/tests/components/motioneye/test_config_flow.py @@ -480,6 +480,24 @@ async def test_advanced_options(hass: HomeAssistant) -> None: ) as mock_setup_entry: await hass.async_block_till_done() + result = await hass.config_entries.options.async_init( + config_entry.entry_id, context={"show_advanced_options": True} + ) + result = await hass.config_entries.options.async_configure( + result["flow_id"], + user_input={ + CONF_WEBHOOK_SET: True, + CONF_WEBHOOK_SET_OVERWRITE: True, + }, + ) + await hass.async_block_till_done() + assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY + assert result["data"][CONF_WEBHOOK_SET] + assert result["data"][CONF_WEBHOOK_SET_OVERWRITE] + assert CONF_STREAM_URL_TEMPLATE not in result["data"] + assert len(mock_setup.mock_calls) == 0 + assert len(mock_setup_entry.mock_calls) == 0 + result = await hass.config_entries.options.async_init( config_entry.entry_id, context={"show_advanced_options": True} )