Skip to content

Commit

Permalink
Change state filter on select to match sensors with route_id instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Kristian Nilsen committed Mar 25, 2023
1 parent 07c65ca commit aeba8c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dist/entur-card.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions src/entur-card-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,15 @@ export class EnturCardEditor
`;
}

// Find all starting with 'sensor.transport'.
const entities = Object.keys(this.hass!.states).filter((k) =>
k.startsWith("sensor.transport")
);
// Filter states to only include sensors, and only those with an attribute containing a "route_id".
const sensorsWithRouteId = Object.values(this.hass!.states)
.filter((entity) => entity.entity_id.startsWith("sensor."))
.filter((sensor) =>
Object.keys(sensor.attributes).some((key) =>
key.toLowerCase().includes("route_id")
)
)
.map((sensor) => sensor.entity_id);

return html`
<div class="card-config">
Expand Down Expand Up @@ -170,7 +175,7 @@ export class EnturCardEditor
fixedMenuPosition
naturalMenuWidth
>
${entities.map(
${sensorsWithRouteId.map(
(entity) => html`
<mwc-list-item .value=${entity}> ${entity} </mwc-list-item>
`
Expand Down

0 comments on commit aeba8c7

Please sign in to comment.