Skip to content

Commit

Permalink
Rewrite findEntitiesBySuffixes to return unsorted array
Browse files Browse the repository at this point in the history
  • Loading branch information
Barma-lej committed Oct 15, 2024
1 parent 44f8f62 commit cbd8427
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/landroid-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,21 +536,18 @@ class LandroidCard extends LitElement {

/**
* Retrieves an object with entity objects from the associatedEntities object by matching the given suffixes
* against the entity IDs.
* against the entity IDs. The resulting object will only contain entities that have a state other than 'unavailable'.
*
* @param {string[]} suffixes - The suffixes to match against the entity IDs.
* @return {Object} An object with the matching entity objects, where the keys are the entity IDs.
*/
findEntitiesBySuffixes(suffixes) {
return Object.values(this.associatedEntities).reduce(
(result, entity) =>
entity &&
entity.state !== 'unavailable' &&
suffixes.some((suffix) => entity.entity_id.endsWith(suffix))
? { ...result, [entity.entity_id]: entity }
: result,
{}
);
return suffixes.reduce((result, suffix) => {
const entitiesWithSuffix = Object.values(this.associatedEntities).filter(
(entity) => entity && entity.state !== 'unavailable' && entity.entity_id.endsWith(suffix)
);
return result.concat(entitiesWithSuffix);
}, []);
}

/**
Expand Down

0 comments on commit cbd8427

Please sign in to comment.