Skip to content

Commit

Permalink
Add support for sorting entitys via the config (esphome#58)
Browse files Browse the repository at this point in the history
Co-authored-by: Jesse Hills <[email protected]>
  • Loading branch information
RFDarter and jesserockz authored May 1, 2024
1 parent 502a2ee commit cbb11b7
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions packages/v3/src/esp-entity-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import "iconify-icon";

interface entityConfig {
unique_id: string;
sorting_weight: number;
domain: string;
id: string;
state: string;
Expand Down Expand Up @@ -98,15 +99,17 @@ export class EntityTable extends LitElement implements RestAction {
this.has_controls = true;
}
this.entities.push(entity);
this.entities.sort((a, b) =>
a.entity_category < b.entity_category
? -1
: a.entity_category == b.entity_category
? a.name < b.name
? -1
: 1
: 1
);
this.entities.sort((a, b) => {
const sortA = a.sorting_weight ?? a.name;
const sortB = b.sorting_weight ?? b.name;
return a.entity_category < b.entity_category
? -1
: a.entity_category == b.entity_category
? sortA < sortB
? -1
: 1
: 1
});
this.requestUpdate();
} else {
if (typeof data.value === "number") {
Expand Down

0 comments on commit cbb11b7

Please sign in to comment.