From 07392e3ff7a49e8b08d199bc37f28360fd1958bf Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Wed, 10 Sep 2025 12:18:58 +0200 Subject: [PATCH] Fix lifx tests opening sockets (#152037) --- tests/components/lifx/test_config_flow.py | 6 ++++- tests/components/lifx/test_light.py | 9 +++++-- tests/components/lifx/test_sensor.py | 31 ++++++++++------------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/tests/components/lifx/test_config_flow.py b/tests/components/lifx/test_config_flow.py index 1b09d742876..aecc71b07e8 100644 --- a/tests/components/lifx/test_config_flow.py +++ b/tests/components/lifx/test_config_flow.py @@ -143,7 +143,11 @@ async def test_discovery_with_existing_device_present(hass: HomeAssistant) -> No ) config_entry.add_to_hass(hass) - with _patch_discovery(), _patch_config_flow_try_connect(no_device=True): + with ( + _patch_device(), + _patch_discovery(), + _patch_config_flow_try_connect(no_device=True), + ): await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() diff --git a/tests/components/lifx/test_light.py b/tests/components/lifx/test_light.py index edb13c259e8..dff43bc21b6 100644 --- a/tests/components/lifx/test_light.py +++ b/tests/components/lifx/test_light.py @@ -2142,7 +2142,12 @@ async def test_light_strip_zones_not_populated_yet(hass: HomeAssistant) -> None: assert bulb.set_power.calls[0][0][0] is True bulb.set_power.reset_mock() - async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=30)) - await hass.async_block_till_done() + with ( + _patch_discovery(device=bulb), + _patch_config_flow_try_connect(device=bulb), + _patch_device(device=bulb), + ): + async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=30)) + await hass.async_block_till_done() state = hass.states.get(entity_id) assert state.state == STATE_ON diff --git a/tests/components/lifx/test_sensor.py b/tests/components/lifx/test_sensor.py index bca4b7cd790..96d3ec4fa4a 100644 --- a/tests/components/lifx/test_sensor.py +++ b/tests/components/lifx/test_sensor.py @@ -57,32 +57,30 @@ async def test_rssi_sensor( await hass.async_block_till_done() entity_id = "sensor.my_bulb_rssi" + assert not hass.states.get(entity_id) entry = entity_registry.entities.get(entity_id) assert entry assert entry.disabled assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION - # Test enabling entity + # Test enabling entity, this will trigger a reload of the config entry updated_entry = entity_registry.async_update_entity( entry.entity_id, disabled_by=None ) + assert updated_entry != entry + assert updated_entry.disabled is False + assert updated_entry.unit_of_measurement == SIGNAL_STRENGTH_DECIBELS_MILLIWATT + with ( _patch_discovery(device=bulb), _patch_config_flow_try_connect(device=bulb), _patch_device(device=bulb), ): - await hass.config_entries.async_reload(config_entry.entry_id) + async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=120)) await hass.async_block_till_done() - assert updated_entry != entry - assert updated_entry.disabled is False - assert updated_entry.unit_of_measurement == SIGNAL_STRENGTH_DECIBELS_MILLIWATT - - async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=120)) - await hass.async_block_till_done() - rssi = hass.states.get(entity_id) assert ( rssi.attributes[ATTR_UNIT_OF_MEASUREMENT] == SIGNAL_STRENGTH_DECIBELS_MILLIWATT @@ -120,26 +118,23 @@ async def test_rssi_sensor_old_firmware( assert entry.disabled assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION - # Test enabling entity + # Test enabling entity, this will trigger a reload of the config entry updated_entry = entity_registry.async_update_entity( entry.entity_id, disabled_by=None ) + assert updated_entry != entry + assert updated_entry.disabled is False + assert updated_entry.unit_of_measurement == SIGNAL_STRENGTH_DECIBELS + with ( _patch_discovery(device=bulb), _patch_config_flow_try_connect(device=bulb), _patch_device(device=bulb), ): - await hass.config_entries.async_reload(config_entry.entry_id) + async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=120)) await hass.async_block_till_done() - assert updated_entry != entry - assert updated_entry.disabled is False - assert updated_entry.unit_of_measurement == SIGNAL_STRENGTH_DECIBELS - - async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=120)) - await hass.async_block_till_done() - rssi = hass.states.get(entity_id) assert rssi.attributes[ATTR_UNIT_OF_MEASUREMENT] == SIGNAL_STRENGTH_DECIBELS assert rssi.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.SIGNAL_STRENGTH