Reduce overhead to lookup items in the entity and device registry (#94568)

This commit is contained in:
J. Nick Koston
2023-06-14 08:47:18 -10:00
committed by GitHub
parent de62082605
commit a0c023d5cb
4 changed files with 35 additions and 6 deletions

View File

@@ -1644,7 +1644,6 @@ async def test_homekit_ignored_missing_devices(
light = entity_registry.async_get_or_create(
"light", "powerwall", "demo", device_id=device_entry.id
)
before_removal = entity_registry.entities.copy()
# Delete the device to make sure we fallback
# to using the platform
device_registry.async_remove_device(device_entry.id)
@@ -1652,7 +1651,23 @@ async def test_homekit_ignored_missing_devices(
await asyncio.sleep(0)
await asyncio.sleep(0)
# Restore the registry
entity_registry.entities = before_removal
entity_registry.async_get_or_create(
"binary_sensor",
"powerwall",
"battery_charging",
device_id=device_entry.id,
original_device_class=BinarySensorDeviceClass.BATTERY_CHARGING,
)
entity_registry.async_get_or_create(
"sensor",
"powerwall",
"battery",
device_id=device_entry.id,
original_device_class=SensorDeviceClass.BATTERY,
)
light = entity_registry.async_get_or_create(
"light", "powerwall", "demo", device_id=device_entry.id
)
hass.states.async_set(light.entity_id, STATE_ON)
hass.states.async_set("light.two", STATE_ON)