pyscript
pyscript copied to clipboard
Get entities by Label
Is it possible to retrieve entities by label? I'm looking to get a bit more dynamic with my functions.
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)