diff --git a/tests/components/flux/test_switch.py b/tests/components/flux/test_switch.py index 1e783c6b649..e594fe5e7ee 100644 --- a/tests/components/flux/test_switch.py +++ b/tests/components/flux/test_switch.py @@ -23,6 +23,7 @@ from tests.common import ( async_mock_service, mock_restore_cache, ) +from tests.components.light.common import MockLight, SetupLightPlatformCallable @pytest.fixture(autouse=True) @@ -136,17 +137,19 @@ async def test_invalid_config_no_lights(hass: HomeAssistant) -> None: async def test_flux_when_switch_is_off( - hass: HomeAssistant, enable_custom_integrations: None + hass: HomeAssistant, + setup_light_platform: SetupLightPlatformCallable, + mock_light_entities: list[MockLight], ) -> None: """Test the flux switch when it is off.""" - platform = getattr(hass.components, "test.light") - platform.init() + setup_light_platform(hass, mock_light_entities) + assert await async_setup_component( hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}} ) await hass.async_block_till_done() - ent1 = platform.ENTITIES[0] + ent1 = mock_light_entities[0] # Verify initial state of light state = hass.states.get(ent1.entity_id) @@ -187,17 +190,19 @@ async def test_flux_when_switch_is_off( async def test_flux_before_sunrise( - hass: HomeAssistant, enable_custom_integrations: None + hass: HomeAssistant, + setup_light_platform: SetupLightPlatformCallable, + mock_light_entities: list[MockLight], ) -> None: """Test the flux switch before sunrise.""" - platform = getattr(hass.components, "test.light") - platform.init() + setup_light_platform(hass, mock_light_entities) + assert await async_setup_component( hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}} ) await hass.async_block_till_done() - ent1 = platform.ENTITIES[0] + ent1 = mock_light_entities[0] # Verify initial state of light state = hass.states.get(ent1.entity_id) @@ -246,17 +251,19 @@ async def test_flux_before_sunrise( async def test_flux_before_sunrise_known_location( - hass: HomeAssistant, enable_custom_integrations: None + hass: HomeAssistant, + setup_light_platform: SetupLightPlatformCallable, + mock_light_entities: list[MockLight], ) -> None: """Test the flux switch before sunrise.""" - platform = getattr(hass.components, "test.light") - platform.init() + setup_light_platform(hass, mock_light_entities) + assert await async_setup_component( hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}} ) await hass.async_block_till_done() - ent1 = platform.ENTITIES[0] + ent1 = mock_light_entities[0] # Verify initial state of light state = hass.states.get(ent1.entity_id) @@ -304,17 +311,19 @@ async def test_flux_before_sunrise_known_location( async def test_flux_after_sunrise_before_sunset( - hass: HomeAssistant, enable_custom_integrations: None + hass: HomeAssistant, + setup_light_platform: SetupLightPlatformCallable, + mock_light_entities: list[MockLight], ) -> None: """Test the flux switch after sunrise and before sunset.""" - platform = getattr(hass.components, "test.light") - platform.init() + setup_light_platform(hass, mock_light_entities) + assert await async_setup_component( hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}} ) await hass.async_block_till_done() - ent1 = platform.ENTITIES[0] + ent1 = mock_light_entities[0] # Verify initial state of light state = hass.states.get(ent1.entity_id) @@ -362,17 +371,19 @@ async def test_flux_after_sunrise_before_sunset( async def test_flux_after_sunset_before_stop( - hass: HomeAssistant, enable_custom_integrations: None + hass: HomeAssistant, + setup_light_platform: SetupLightPlatformCallable, + mock_light_entities: list[MockLight], ) -> None: """Test the flux switch after sunset and before stop.""" - platform = getattr(hass.components, "test.light") - platform.init() + setup_light_platform(hass, mock_light_entities) + assert await async_setup_component( hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}} ) await hass.async_block_till_done() - ent1 = platform.ENTITIES[0] + ent1 = mock_light_entities[0] # Verify initial state of light state = hass.states.get(ent1.entity_id) @@ -421,17 +432,19 @@ async def test_flux_after_sunset_before_stop( async def test_flux_after_stop_before_sunrise( - hass: HomeAssistant, enable_custom_integrations: None + hass: HomeAssistant, + setup_light_platform: SetupLightPlatformCallable, + mock_light_entities: list[MockLight], ) -> None: """Test the flux switch after stop and before sunrise.""" - platform = getattr(hass.components, "test.light") - platform.init() + setup_light_platform(hass, mock_light_entities) + assert await async_setup_component( hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}} ) await hass.async_block_till_done() - ent1 = platform.ENTITIES[0] + ent1 = mock_light_entities[0] # Verify initial state of light state = hass.states.get(ent1.entity_id) @@ -479,17 +492,19 @@ async def test_flux_after_stop_before_sunrise( async def test_flux_with_custom_start_stop_times( - hass: HomeAssistant, enable_custom_integrations: None + hass: HomeAssistant, + setup_light_platform: SetupLightPlatformCallable, + mock_light_entities: list[MockLight], ) -> None: """Test the flux with custom start and stop times.""" - platform = getattr(hass.components, "test.light") - platform.init() + setup_light_platform(hass, mock_light_entities) + assert await async_setup_component( hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}} ) await hass.async_block_till_done() - ent1 = platform.ENTITIES[0] + ent1 = mock_light_entities[0] # Verify initial state of light state = hass.states.get(ent1.entity_id) @@ -539,20 +554,22 @@ async def test_flux_with_custom_start_stop_times( async def test_flux_before_sunrise_stop_next_day( - hass: HomeAssistant, enable_custom_integrations: None + hass: HomeAssistant, + setup_light_platform: SetupLightPlatformCallable, + mock_light_entities: list[MockLight], ) -> None: """Test the flux switch before sunrise. This test has the stop_time on the next day (after midnight). """ - platform = getattr(hass.components, "test.light") - platform.init() + setup_light_platform(hass, mock_light_entities) + assert await async_setup_component( hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}} ) await hass.async_block_till_done() - ent1 = platform.ENTITIES[0] + ent1 = mock_light_entities[0] # Verify initial state of light state = hass.states.get(ent1.entity_id) @@ -601,20 +618,22 @@ async def test_flux_before_sunrise_stop_next_day( async def test_flux_after_sunrise_before_sunset_stop_next_day( - hass: HomeAssistant, enable_custom_integrations: None + hass: HomeAssistant, + setup_light_platform: SetupLightPlatformCallable, + mock_light_entities: list[MockLight], ) -> None: """Test the flux switch after sunrise and before sunset. This test has the stop_time on the next day (after midnight). """ - platform = getattr(hass.components, "test.light") - platform.init() + setup_light_platform(hass, mock_light_entities) + assert await async_setup_component( hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}} ) await hass.async_block_till_done() - ent1 = platform.ENTITIES[0] + ent1 = mock_light_entities[0] # Verify initial state of light state = hass.states.get(ent1.entity_id) @@ -664,20 +683,23 @@ async def test_flux_after_sunrise_before_sunset_stop_next_day( @pytest.mark.parametrize("x", [0, 1]) async def test_flux_after_sunset_before_midnight_stop_next_day( - hass: HomeAssistant, x, enable_custom_integrations: None + hass: HomeAssistant, + x, + setup_light_platform: SetupLightPlatformCallable, + mock_light_entities: list[MockLight], ) -> None: """Test the flux switch after sunset and before stop. This test has the stop_time on the next day (after midnight). """ - platform = getattr(hass.components, "test.light") - platform.init() + setup_light_platform(hass, mock_light_entities) + assert await async_setup_component( hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}} ) await hass.async_block_till_done() - ent1 = platform.ENTITIES[0] + ent1 = mock_light_entities[0] # Verify initial state of light state = hass.states.get(ent1.entity_id) @@ -726,20 +748,22 @@ async def test_flux_after_sunset_before_midnight_stop_next_day( async def test_flux_after_sunset_after_midnight_stop_next_day( - hass: HomeAssistant, enable_custom_integrations: None + hass: HomeAssistant, + setup_light_platform: SetupLightPlatformCallable, + mock_light_entities: list[MockLight], ) -> None: """Test the flux switch after sunset and before stop. This test has the stop_time on the next day (after midnight). """ - platform = getattr(hass.components, "test.light") - platform.init() + setup_light_platform(hass, mock_light_entities) + assert await async_setup_component( hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}} ) await hass.async_block_till_done() - ent1 = platform.ENTITIES[0] + ent1 = mock_light_entities[0] # Verify initial state of light state = hass.states.get(ent1.entity_id) @@ -788,20 +812,22 @@ async def test_flux_after_sunset_after_midnight_stop_next_day( async def test_flux_after_stop_before_sunrise_stop_next_day( - hass: HomeAssistant, enable_custom_integrations: None + hass: HomeAssistant, + setup_light_platform: SetupLightPlatformCallable, + mock_light_entities: list[MockLight], ) -> None: """Test the flux switch after stop and before sunrise. This test has the stop_time on the next day (after midnight). """ - platform = getattr(hass.components, "test.light") - platform.init() + setup_light_platform(hass, mock_light_entities) + assert await async_setup_component( hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}} ) await hass.async_block_till_done() - ent1 = platform.ENTITIES[0] + ent1 = mock_light_entities[0] # Verify initial state of light state = hass.states.get(ent1.entity_id) @@ -850,17 +876,19 @@ async def test_flux_after_stop_before_sunrise_stop_next_day( async def test_flux_with_custom_colortemps( - hass: HomeAssistant, enable_custom_integrations: None + hass: HomeAssistant, + setup_light_platform: SetupLightPlatformCallable, + mock_light_entities: list[MockLight], ) -> None: """Test the flux with custom start and stop colortemps.""" - platform = getattr(hass.components, "test.light") - platform.init() + setup_light_platform(hass, mock_light_entities) + assert await async_setup_component( hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}} ) await hass.async_block_till_done() - ent1 = platform.ENTITIES[0] + ent1 = mock_light_entities[0] # Verify initial state of light state = hass.states.get(ent1.entity_id) @@ -911,17 +939,19 @@ async def test_flux_with_custom_colortemps( async def test_flux_with_custom_brightness( - hass: HomeAssistant, enable_custom_integrations: None + hass: HomeAssistant, + setup_light_platform: SetupLightPlatformCallable, + mock_light_entities: list[MockLight], ) -> None: """Test the flux with custom start and stop colortemps.""" - platform = getattr(hass.components, "test.light") - platform.init() + setup_light_platform(hass, mock_light_entities) + assert await async_setup_component( hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}} ) await hass.async_block_till_done() - ent1 = platform.ENTITIES[0] + ent1 = mock_light_entities[0] # Verify initial state of light state = hass.states.get(ent1.entity_id) @@ -971,17 +1001,19 @@ async def test_flux_with_custom_brightness( async def test_flux_with_multiple_lights( - hass: HomeAssistant, enable_custom_integrations: None + hass: HomeAssistant, + setup_light_platform: SetupLightPlatformCallable, + mock_light_entities: list[MockLight], ) -> None: """Test the flux switch with multiple light entities.""" - platform = getattr(hass.components, "test.light") - platform.init() + setup_light_platform(hass, mock_light_entities) + assert await async_setup_component( hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}} ) await hass.async_block_till_done() - ent1, ent2, ent3 = platform.ENTITIES + ent1, ent2, ent3 = mock_light_entities await hass.services.async_call( light.DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: ent2.entity_id}, blocking=True @@ -1052,17 +1084,19 @@ async def test_flux_with_multiple_lights( async def test_flux_with_mired( - hass: HomeAssistant, enable_custom_integrations: None + hass: HomeAssistant, + setup_light_platform: SetupLightPlatformCallable, + mock_light_entities: list[MockLight], ) -> None: """Test the flux switch´s mode mired.""" - platform = getattr(hass.components, "test.light") - platform.init() + setup_light_platform(hass, mock_light_entities) + assert await async_setup_component( hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}} ) await hass.async_block_till_done() - ent1 = platform.ENTITIES[0] + ent1 = mock_light_entities[0] # Verify initial state of light state = hass.states.get(ent1.entity_id) @@ -1109,17 +1143,19 @@ async def test_flux_with_mired( async def test_flux_with_rgb( - hass: HomeAssistant, enable_custom_integrations: None + hass: HomeAssistant, + setup_light_platform: SetupLightPlatformCallable, + mock_light_entities: list[MockLight], ) -> None: """Test the flux switch´s mode rgb.""" - platform = getattr(hass.components, "test.light") - platform.init() + setup_light_platform(hass, mock_light_entities) + assert await async_setup_component( hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}} ) await hass.async_block_till_done() - ent1 = platform.ENTITIES[0] + ent1 = mock_light_entities[0] # Verify initial state of light state = hass.states.get(ent1.entity_id)