Fix lifx tests opening sockets (#152037)

This commit is contained in:
Erik Montnemery
2025-09-10 12:18:58 +02:00
committed by GitHub
parent 3e39f77e92
commit 07392e3ff7
3 changed files with 25 additions and 21 deletions

View File

@@ -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()

View File

@@ -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

View File

@@ -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