From d95f0d4bc6be05030e4eb271e6969f04b9633fc5 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Thu, 27 Nov 2025 10:52:11 -0800 Subject: [PATCH] Fix xfail and skipped tests to properly pass (#1307) --- tests/test_config_flow.py | 33 +++++++++++++++++++-------------- tests/test_switch.py | 14 +++++++++----- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/tests/test_config_flow.py b/tests/test_config_flow.py index 0b9609d3..02ed6d42 100644 --- a/tests/test_config_flow.py +++ b/tests/test_config_flow.py @@ -1,6 +1,5 @@ """Test Adaptive Lighting config flow.""" -import pytest from homeassistant.components.adaptive_lighting.const import ( CONF_SUNRISE_TIME, CONF_SUNSET_TIME, @@ -115,14 +114,13 @@ async def test_import_twice(hass): ) -# TODO: Fix, broken for all supported versions -# But in ≤2024.5 it gives homeassistant.config_entries.UnknownEntry: cd69dbda65bd3f86e9a32d974cdfa23f -# and ≥2024.6 it times out -# NOTE: Just skip this test for now, currently (2025-06-15) I cannot figure out -# what this test is even testing. -async def test_changing_options_when_using_yaml(hass): - """Test changing options when using YAML.""" - pytest.skip(reason="TODO: Fix, broken for all supported versions") +async def test_options_flow_for_yaml_import(hass): + """Test that options flow for YAML-imported entries shows empty form. + + When a config entry is imported from YAML (source=SOURCE_IMPORT), + the options flow should show an empty form since the user should + modify the YAML configuration directly, not through the UI. + """ entry = MockConfigEntry( domain=DOMAIN, title=DEFAULT_NAME, @@ -132,11 +130,18 @@ async def test_changing_options_when_using_yaml(hass): ) entry.add_to_hass(hass) - await hass.block_till_done() + # For YAML imports, the switch setup requires the unique_id to be in + # hass.data[DOMAIN]["__yaml__"], otherwise it deletes the entry. + # This simulates what async_step_import does. + hass.data.setdefault(DOMAIN, {}).setdefault("__yaml__", set()).add(entry.unique_id) + await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done() result = await hass.config_entries.options.async_init(entry.entry_id) - result = await hass.config_entries.options.async_configure( - result["flow_id"], - user_input={}, - ) + + # For YAML imports, the options flow shows an empty form (data_schema=None) + # This is intentional - users should modify YAML, not UI + assert result["type"] == FlowResultType.FORM + assert result["step_id"] == "init" + assert result.get("data_schema") is None diff --git a/tests/test_switch.py b/tests/test_switch.py index 5011ebc6..e85cecb9 100644 --- a/tests/test_switch.py +++ b/tests/test_switch.py @@ -1296,13 +1296,17 @@ async def test_restore_off_state(hass, state): assert not _switch.is_on -@pytest.mark.xfail(reason="Offset is larger than half a day") async def test_offset_too_large(hass): - """Test that update fails when the offset is too large.""" + """Test that update fails when the sunrise offset is too large. + + A 12-hour offset causes sun events to be out of order (e.g., sunrise after sunset), + which makes the adaptive lighting algorithm fail with a ValueError. + """ _, switch = await setup_switch(hass, {CONF_SUNRISE_OFFSET: 3600 * 12}) - await switch._update_attrs_and_maybe_adapt_lights( - context=switch.create_context("test"), - ) + with pytest.raises(ValueError, match="sun events.*not in the expected order"): + await switch._update_attrs_and_maybe_adapt_lights( + context=switch.create_context("test"), + ) await hass.async_block_till_done()