Fix saving options with missing ignored sources in BraviaTV (#83891)

fix https://github.com/home-assistant/core/issues/83217
fixes undefined
This commit is contained in:
Artem Draft 2022-12-13 10:45:04 +03:00 committed by GitHub
parent aa23a125bf
commit e32074c74e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -264,6 +264,12 @@ class BraviaTVOptionsFlowHandler(config_entries.OptionsFlowWithConfigEntry):
sources = coordinator.source_map.values()
source_list = [item["title"] for item in sources]
ignored_sources = self.options.get(CONF_IGNORED_SOURCES, [])
for item in ignored_sources:
if item not in source_list:
source_list.append(item)
self.data_schema = vol.Schema(
{
vol.Optional(CONF_IGNORED_SOURCES): cv.multi_select(source_list),

View File

@ -422,6 +422,19 @@ async def test_options_flow(hass: HomeAssistant) -> None:
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
assert config_entry.options == {CONF_IGNORED_SOURCES: ["HDMI 1", "HDMI 2"]}
# Test that saving with missing sources is ok
with patch(
"pybravia.BraviaTV.get_external_status",
return_value=BRAVIA_SOURCES[1:],
):
result = await hass.config_entries.options.async_init(config_entry.entry_id)
result = await hass.config_entries.options.async_configure(
result["flow_id"], user_input={CONF_IGNORED_SOURCES: ["HDMI 1"]}
)
await hass.async_block_till_done()
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
assert config_entry.options == {CONF_IGNORED_SOURCES: ["HDMI 1"]}
async def test_options_flow_error(hass: HomeAssistant) -> None:
"""Test config flow options."""