#Negating the integration filter on a selector?

1 messages · Page 1 of 1 (latest)

valid tundra
#

I'm configuring a field for a script and I would like to have it allow a certain class of device from all integrations except one, ie the opposite of this selector:

      selector:
        target:
          entity:
            domain: media_player
            integration: alexa_media

Is that possible?

tall drift
#

I don't think it's possible. You could make the script handle it to set a persistent notification that a unsupported entity is selected.

Why not that one integration?

valid tundra
tall drift
#

Ahh, then I would just make a single field. But when you want to do the TTS, just filter between Alexa and non-alexa

valid tundra
#

hmm, how would I filter the array of entity IDs by which integration they're from?

tall drift
#
{% set alexa_entities = input_entities | select('in', integration_entities('alexa_media')) | list %}
#

And the others:

{% set non_alexa_entities = input_entities | reject('in', integration_entities('alexa_media')) | list %}
valid tundra
#

nice, thanks

valid tundra
valid tundra
#

I feel like I’m probably missing something because that ended up way more complex than I expected, to be able to work with all the possible ways the entity selector can output things, but it works.

tall drift
#

Looks nice. But isn't all the extra work just to make sure it's a list? And also filter non media players? For last you could also trust the UI and just let it make errors when people force in a non-media player

#

Ah, yeah, also to support devices, area's etc. Yeahhhhhh, that's a bit of a mess indeed

#

I just never messed with targets and just force entity id 😄

smoky crow
#

also, just cause I looked at it again, that template can be drastically simplified

#

sry, got sidetracked

#

anyways, simplified

      expanded_targets: >
        {# Create the namespace object we'll use to store all our working data #}
        {% set data = namespace(expanded_targets=[]) %}

        {% macro dummy(someValue, returns) %}
        {%   do returns(someValue) %}
        {% endmacro %}
    
        {# Declare our helper macros as functions, so they can return values #}
        {% set dummy = dummy | as_function %}
        
        {% set funcs = {"device_id": device_entities, "area_id": area_entities, "label_id": label_entities} %}
        
        {% for key, value in target.items() %}
          {% set entities = funcs.get(key, dummy) %}
          {% set items = [value] if value is not list else value %}
          {% set data.expanded_targets = data.expanded_targets + entities(value) | select("match", "media_player") | list %}
        {% endfor %}
        {{ data.expanded_targets | unique | list }}
#

You were doing a couple things that weren't necessary:

  1. No need to create a macro when you use it once unless you need a function.
  2. use a dictionary when possible if you're matching keys and provide a default for everything else
  3. You're using expand on a list of entities to get the entity_id, when it's already a list of entity_ids. That's effectively slowing your template down considerably. Just use the list of entities that you already have.