Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get entities by Label #678

Open
b3tts32 opened this issue Jan 13, 2025 · 2 comments
Open

Get entities by Label #678

b3tts32 opened this issue Jan 13, 2025 · 2 comments

Comments

@b3tts32
Copy link

b3tts32 commented Jan 13, 2025

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

@ALERTua
Copy link
Contributor

ALERTua commented Jan 13, 2025

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@ALERTua @b3tts32 and others