remove unreachable code

This commit is contained in:
J. Nick Koston
2025-06-24 00:04:17 +02:00
parent 2ecd334f80
commit 0c72d76869
2 changed files with 3 additions and 109 deletions

View File

@ -79,8 +79,9 @@ def async_static_info_updated(
# Entity has switched devices, update its device assignment
unique_id = build_unique_id(device_info.mac_address, info)
entity_id = ent_reg.async_get_entity_id(platform.domain, DOMAIN, unique_id)
if not entity_id:
continue
# entity_id should never be None here because old_info is not None,
# which means the entity was previously created and is in the registry
assert entity_id is not None
# Determine the new device
if info.device_id:

View File

@ -1030,110 +1030,3 @@ async def test_entity_switches_between_devices(
sensor_entity = entity_registry.async_get("binary_sensor.test_sensor")
assert sensor_entity is not None
assert sensor_entity.device_id == main_device.id
async def test_entity_switches_devices_entity_not_in_registry(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
device_registry: dr.DeviceRegistry,
mock_client: APIClient,
mock_esphome_device: MockESPHomeDeviceType,
) -> None:
"""Test entity device switch when one entity is not in registry."""
# Define sub devices
sub_devices = [
SubDeviceInfo(device_id=11111111, name="Sub Device 1", area_id=0),
SubDeviceInfo(device_id=22222222, name="Sub Device 2", area_id=0),
]
device_info = {
"devices": sub_devices,
}
# Create initial entities on sub device 1
entity_info = [
BinarySensorInfo(
object_id="sensor1",
key=1,
name="Test Sensor 1",
unique_id="sensor1",
device_id=11111111,
),
BinarySensorInfo(
object_id="sensor2",
key=2,
name="Test Sensor 2",
unique_id="sensor2",
device_id=11111111,
),
]
states = [
BinarySensorState(key=1, state=True, missing_state=False),
BinarySensorState(key=2, state=False, missing_state=False),
]
device = await mock_esphome_device(
mock_client=mock_client,
device_info=device_info,
entity_info=entity_info,
states=states,
)
# Verify both entities are created on sub device 1
sub_device_1 = device_registry.async_get_device(
identifiers={(DOMAIN, f"{device.device_info.mac_address}_11111111")}
)
assert sub_device_1 is not None
sensor1_entity = entity_registry.async_get("binary_sensor.test_sensor1")
assert sensor1_entity is not None
assert sensor1_entity.device_id == sub_device_1.id
sensor2_entity = entity_registry.async_get("binary_sensor.test_sensor2")
assert sensor2_entity is not None
assert sensor2_entity.device_id == sub_device_1.id
# Remove sensor1 from registry
entity_registry.async_remove(sensor1_entity.entity_id)
# Verify it's removed
assert entity_registry.async_get("binary_sensor.test_sensor1") is None
# Try to update both entities to move to sub device 2
updated_entity_info = [
BinarySensorInfo(
object_id="sensor1",
key=1,
name="Test Sensor 1",
unique_id="sensor1",
device_id=22222222, # Try to move to sub device 2
),
BinarySensorInfo(
object_id="sensor2",
key=2,
name="Test Sensor 2",
unique_id="sensor2",
device_id=22222222, # Move to sub device 2
),
]
# Update should not fail even though sensor1 is not in registry
mock_client.list_entities_services = AsyncMock(
return_value=(updated_entity_info, [])
)
await device.mock_disconnect(expected_disconnect=False)
await device.mock_connect()
# Sensor1 should remain not in registry
assert entity_registry.async_get("binary_sensor.test_sensor1") is None
# But sensor2 should have moved to sub device 2
sub_device_2 = device_registry.async_get_device(
identifiers={(DOMAIN, f"{device.device_info.mac_address}_22222222")}
)
assert sub_device_2 is not None
sensor2_entity = entity_registry.async_get("binary_sensor.test_sensor2")
assert sensor2_entity is not None
assert sensor2_entity.device_id == sub_device_2.id