From 5b5250cae7605542cc488cae658271d66ad5842c Mon Sep 17 00:00:00 2001 From: Tsvi Mostovicz Date: Tue, 4 Jun 2024 16:10:35 +0000 Subject: [PATCH] Improve tests and fix import --- .../components/jewish_calendar/config_flow.py | 15 +++++++++++++- .../jewish_calendar/test_config_flow.py | 20 ++++++++++--------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/jewish_calendar/config_flow.py b/homeassistant/components/jewish_calendar/config_flow.py index 626dc168db8..8f04d73915f 100644 --- a/homeassistant/components/jewish_calendar/config_flow.py +++ b/homeassistant/components/jewish_calendar/config_flow.py @@ -100,10 +100,23 @@ class JewishCalendarConfigFlow(ConfigFlow, domain=DOMAIN): ) -> ConfigFlowResult: """Handle the initial step.""" if user_input is not None: + _options = {} + if CONF_CANDLE_LIGHT_MINUTES in user_input: + _options[CONF_CANDLE_LIGHT_MINUTES] = user_input[ + CONF_CANDLE_LIGHT_MINUTES + ] + del user_input[CONF_CANDLE_LIGHT_MINUTES] + if CONF_HAVDALAH_OFFSET_MINUTES in user_input: + _options[CONF_HAVDALAH_OFFSET_MINUTES] = user_input[ + CONF_HAVDALAH_OFFSET_MINUTES + ] + del user_input[CONF_HAVDALAH_OFFSET_MINUTES] if CONF_LOCATION in user_input: user_input[CONF_LATITUDE] = user_input[CONF_LOCATION][CONF_LATITUDE] user_input[CONF_LONGITUDE] = user_input[CONF_LOCATION][CONF_LONGITUDE] - return self.async_create_entry(title=DEFAULT_NAME, data=user_input) + return self.async_create_entry( + title=DEFAULT_NAME, data=user_input, options=_options + ) return self.async_show_form( step_id="user", diff --git a/tests/components/jewish_calendar/test_config_flow.py b/tests/components/jewish_calendar/test_config_flow.py index 192970a0cd9..83cc233bb89 100644 --- a/tests/components/jewish_calendar/test_config_flow.py +++ b/tests/components/jewish_calendar/test_config_flow.py @@ -12,7 +12,6 @@ from homeassistant.components.jewish_calendar.const import ( CONF_HAVDALAH_OFFSET_MINUTES, DEFAULT_CANDLE_LIGHT, DEFAULT_DIASPORA, - DEFAULT_HAVDALAH_OFFSET_MINUTES, DEFAULT_LANGUAGE, DOMAIN, ) @@ -75,10 +74,8 @@ async def test_import_no_options(hass: HomeAssistant, language, diaspora) -> Non entries = hass.config_entries.async_entries(DOMAIN) assert len(entries) == 1 - assert entries[0].data == conf[DOMAIN] | { - CONF_CANDLE_LIGHT_MINUTES: DEFAULT_CANDLE_LIGHT, - CONF_HAVDALAH_OFFSET_MINUTES: DEFAULT_HAVDALAH_OFFSET_MINUTES, - } + for entry_key, entry_val in entries[0].data.items(): + assert entry_val == conf[DOMAIN][entry_key] async def test_import_with_options(hass: HomeAssistant) -> None: @@ -101,7 +98,10 @@ async def test_import_with_options(hass: HomeAssistant) -> None: entries = hass.config_entries.async_entries(DOMAIN) assert len(entries) == 1 - assert entries[0].data == conf[DOMAIN] + for entry_key, entry_val in entries[0].data.items(): + assert entry_val == conf[DOMAIN][entry_key] + for entry_key, entry_val in entries[0].options.items(): + assert entry_val == conf[DOMAIN][entry_key] async def test_single_instance_allowed( @@ -137,11 +137,13 @@ async def test_options(hass: HomeAssistant, mock_config_entry: MockConfigEntry) ) assert result["type"] is FlowResultType.CREATE_ENTRY - assert result["data"][CONF_CANDLE_LIGHT_MINUTES] == 25 - assert result["data"][CONF_HAVDALAH_OFFSET_MINUTES] == 34 + entries = hass.config_entries.async_entries(DOMAIN) + assert len(entries) == 1 + assert entries[0].options[CONF_CANDLE_LIGHT_MINUTES] == 25 + assert entries[0].options[CONF_HAVDALAH_OFFSET_MINUTES] == 34 -async def test_options_updates_sensors( +async def test_options_reconfigure( hass: HomeAssistant, mock_config_entry: MockConfigEntry ) -> None: """Test that updating the options of the Jewish Calendar integration triggers a value update."""