diff --git a/packages/v3/src/esp-entity-table.ts b/packages/v3/src/esp-entity-table.ts index 002d490..ef4c98d 100644 --- a/packages/v3/src/esp-entity-table.ts +++ b/packages/v3/src/esp-entity-table.ts @@ -10,6 +10,7 @@ import "iconify-icon"; interface entityConfig { unique_id: string; + sorting_weight: number; domain: string; id: string; state: string; @@ -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") {