Remove async_get_device_class_lookup from entity_registry (#114212)

This function was only ever used in homekit, and since there is
now an index of devices in the entity registry, homekit no longer
uses it.

I searched github code for all references to async_get_device_class_lookup
and the only think I could find using it were forks of core. It seems
unlikely that any custom components are affected by removing this
function
pull/114221/head
J. Nick Koston 2024-03-25 22:22:53 -10:00 committed by GitHub
parent 3f545cb3d3
commit 54a69a2687
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 0 additions and 102 deletions

View File

@ -643,29 +643,6 @@ class EntityRegistry(BaseRegistry):
run_immediately=True,
)
@callback
def async_get_device_class_lookup(
self, domain_device_classes: set[tuple[str, str | None]]
) -> dict[str, dict[tuple[str, str | None], str]]:
"""Return a lookup of entity ids for devices which have matching entities.
Entities must match a set of (domain, device_class) tuples.
The result is indexed by device_id, then by the matching (domain, device_class)
"""
lookup: dict[str, dict[tuple[str, str | None], str]] = {}
for entity in self.entities.values():
if not entity.device_id:
continue
device_class = entity.device_class or entity.original_device_class
domain_device_class = (entity.domain, device_class)
if domain_device_class not in domain_device_classes:
continue
if entity.device_id not in lookup:
lookup[entity.device_id] = {domain_device_class: entity.entity_id}
else:
lookup[entity.device_id][domain_device_class] = entity.entity_id
return lookup
@callback
def async_is_registered(self, entity_id: str) -> bool:
"""Check if an entity_id is currently registered."""

View File

@ -954,85 +954,6 @@ async def test_restore_states(
assert hass.states.get("light.all_info_set") is None
async def test_async_get_device_class_lookup(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test registry device class lookup."""
hass.set_state(CoreState.not_running)
entity_registry.async_get_or_create(
"binary_sensor",
"light",
"battery_charging",
device_id="light_device_entry_id",
original_device_class="battery_charging",
)
entity_registry.async_get_or_create(
"sensor",
"light",
"battery",
device_id="light_device_entry_id",
original_device_class="battery",
)
entity_registry.async_get_or_create(
"light", "light", "demo", device_id="light_device_entry_id"
)
entity_registry.async_get_or_create(
"binary_sensor",
"vacuum",
"battery_charging",
device_id="vacuum_device_entry_id",
original_device_class="battery_charging",
)
entity_registry.async_get_or_create(
"sensor",
"vacuum",
"battery",
device_id="vacuum_device_entry_id",
original_device_class="battery",
)
entity_registry.async_get_or_create(
"vacuum", "vacuum", "demo", device_id="vacuum_device_entry_id"
)
entity_registry.async_get_or_create(
"binary_sensor",
"remote",
"battery_charging",
device_id="remote_device_entry_id",
original_device_class="battery_charging",
)
entity_registry.async_get_or_create(
"remote", "remote", "demo", device_id="remote_device_entry_id"
)
device_lookup = entity_registry.async_get_device_class_lookup(
{("binary_sensor", "battery_charging"), ("sensor", "battery")}
)
assert device_lookup == {
"remote_device_entry_id": {
(
"binary_sensor",
"battery_charging",
): "binary_sensor.remote_battery_charging"
},
"light_device_entry_id": {
(
"binary_sensor",
"battery_charging",
): "binary_sensor.light_battery_charging",
("sensor", "battery"): "sensor.light_battery",
},
"vacuum_device_entry_id": {
(
"binary_sensor",
"battery_charging",
): "binary_sensor.vacuum_battery_charging",
("sensor", "battery"): "sensor.vacuum_battery",
},
}
async def test_remove_device_removes_entities(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,