mirror of
https://github.com/home-assistant/core.git
synced 2025-08-13 17:45:19 +02:00
Improve tests and fix import
This commit is contained in:
@@ -100,10 +100,23 @@ class JewishCalendarConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle the initial step."""
|
"""Handle the initial step."""
|
||||||
if user_input is not None:
|
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:
|
if CONF_LOCATION in user_input:
|
||||||
user_input[CONF_LATITUDE] = user_input[CONF_LOCATION][CONF_LATITUDE]
|
user_input[CONF_LATITUDE] = user_input[CONF_LOCATION][CONF_LATITUDE]
|
||||||
user_input[CONF_LONGITUDE] = user_input[CONF_LOCATION][CONF_LONGITUDE]
|
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(
|
return self.async_show_form(
|
||||||
step_id="user",
|
step_id="user",
|
||||||
|
@@ -12,7 +12,6 @@ from homeassistant.components.jewish_calendar.const import (
|
|||||||
CONF_HAVDALAH_OFFSET_MINUTES,
|
CONF_HAVDALAH_OFFSET_MINUTES,
|
||||||
DEFAULT_CANDLE_LIGHT,
|
DEFAULT_CANDLE_LIGHT,
|
||||||
DEFAULT_DIASPORA,
|
DEFAULT_DIASPORA,
|
||||||
DEFAULT_HAVDALAH_OFFSET_MINUTES,
|
|
||||||
DEFAULT_LANGUAGE,
|
DEFAULT_LANGUAGE,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
@@ -75,10 +74,8 @@ async def test_import_no_options(hass: HomeAssistant, language, diaspora) -> Non
|
|||||||
|
|
||||||
entries = hass.config_entries.async_entries(DOMAIN)
|
entries = hass.config_entries.async_entries(DOMAIN)
|
||||||
assert len(entries) == 1
|
assert len(entries) == 1
|
||||||
assert entries[0].data == conf[DOMAIN] | {
|
for entry_key, entry_val in entries[0].data.items():
|
||||||
CONF_CANDLE_LIGHT_MINUTES: DEFAULT_CANDLE_LIGHT,
|
assert entry_val == conf[DOMAIN][entry_key]
|
||||||
CONF_HAVDALAH_OFFSET_MINUTES: DEFAULT_HAVDALAH_OFFSET_MINUTES,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async def test_import_with_options(hass: HomeAssistant) -> None:
|
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)
|
entries = hass.config_entries.async_entries(DOMAIN)
|
||||||
assert len(entries) == 1
|
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(
|
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["type"] is FlowResultType.CREATE_ENTRY
|
||||||
assert result["data"][CONF_CANDLE_LIGHT_MINUTES] == 25
|
entries = hass.config_entries.async_entries(DOMAIN)
|
||||||
assert result["data"][CONF_HAVDALAH_OFFSET_MINUTES] == 34
|
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
|
hass: HomeAssistant, mock_config_entry: MockConfigEntry
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that updating the options of the Jewish Calendar integration triggers a value update."""
|
"""Test that updating the options of the Jewish Calendar integration triggers a value update."""
|
||||||
|
Reference in New Issue
Block a user