Allow globs and regex for device names. Fix #20

This commit is contained in:
Thomas Lovén 2019-11-08 08:42:42 +01:00
parent 05a3d0a9c5
commit 65490abff1
4 changed files with 30 additions and 10 deletions

View File

@ -226,7 +226,6 @@ filter:
Show everything that has "light" in its name, but isn't a light, and all switches in the living room:
```yaml
type: custom:auto-entities
show_empty: false
card:
type: entities
title: Lights on
@ -241,5 +240,17 @@ filter:
area: Living Room
```
List every sensor belonging to any iPhone:
```yaml
type: custom:auto-entities
card:
type: entities
title: Phones
show_header_toggle: false
filter:
include:
- device: /iPhone/
```
---
<a href="https://www.buymeacoffee.com/uqD6KHCdJ" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/white_img.png" alt="Buy Me A Coffee" style="height: auto !important;width: auto !important;" ></a>

File diff suppressed because one or more lines are too long

View File

@ -92,16 +92,25 @@ export function entity_filter(hass, filter) {
break;
case "device":
const _deviceEntities = deviceEntities(deviceByName(value));
if(!_deviceEntities.includes(entity.entity_id))
return false;
let _deviceMatch = false;
for(const d of window.cardToolsData.devices) {
if (match(value, d.name)){
if(deviceEntities(d).includes(entity.entity_id))
_deviceMatch = true;
}
}
if(!_deviceMatch) return false;
break;
case "area":
const _areaDevices = areaDevices(areaByName(value));
const _areaEntities = _areaDevices.flatMap(deviceEntities);
if(!_areaEntities.includes(entity.entity_id))
return false;
let _areaMatch = false;
for (const a of window.cardToolsData.areas) {
if(match(value, a.name)) {
if(areaDevices(a).flatMap(deviceEntities).includes(entity.entity_id))
_areaMatch = true;
}
}
if(!_areaMatch) return false;
break;
default:

View File

@ -75,7 +75,7 @@ class AutoEntities extends LitElement {
// Sort everything
entities = entities.sort(entity_sorter(this.hass, this._config.sort));
}
return entities;
}