postlund / search-card

Quickly search for entities from a Lovelace card.
MIT License
104 stars 13 forks source link

Search using friendly name #4

Closed indykoning closed 5 years ago

indykoning commented 5 years ago

After trying it out for a bit i thought the search wasn't fully working for some entities for me.

Then i found out that the entities i couldn't find had a unfriendly entity id like 'eurodomest_06_435' when i searched with that it did find my "living room light" since i only changed the friendly name in the customization.

It would be great if the search function would search the entity id and friendly names of entities.

Other than that i haven't ran into any issues so far and am loving this!

postlund commented 5 years ago

Yeah, you are right. Currently it searches on entity id solely, but searching on friendly_name (with fallback on entity_id) would be more convenient. That was my intention all along, also supporting things like regular expressions too. Will add that once I have some free time.

Great that you find it useful! 😄

indykoning commented 5 years ago

Finally got myself some time to tinker with it, but my internet is acting up so i can't make a proper PR right now. You'd want to replace the for loop at #88 with

    for (var entity_id in this.hass.states) {
      if (
          (entity_id.toLowerCase().indexOf(searchText) >= 0) ||
          (
            "friendly_name" in this.hass.states[entity_id].attributes &&
            this.hass.states[entity_id].attributes.friendly_name.toLowerCase().indexOf(searchText) >= 0
          )
        ) {
        this.data.push(entity_id);
      }
    }

I added tolowerCase() to both to make it case insensitive, i also did this to the searchtext at #81

indykoning commented 5 years ago

Since the internet is back and the other person doing this hasn't updated his PR yet, i have taken some of his code and improved on it in #7

postlund commented 5 years ago

Closed #7, so this should be fixed now!