pyscript icon indicating copy to clipboard operation
pyscript copied to clipboard

Get entities by Label

Open b3tts32 opened this issue 11 months ago • 2 comments

Is it possible to retrieve entities by label? I'm looking to get a bit more dynamic with my functions.

b3tts32 avatar Jan 13 '25 03:01 b3tts32

This is how I use it.

from homeassistant.helpers import device_registry

def ha_devices(self, filter_func=None) -> list[device_registry.DeviceEntry]:
    registry = device_registry.async_get(hass)
    output = registry.devices.values()
    if filter_func:
        output = filter(filter_func, output)
    return list(output)

devices_to_disable = ha_devices(filter_func=lambda _: 'to_disable' in _.labels and not _.disabled)

ALERTua avatar Jan 13 '25 08:01 ALERTua