mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-25 05:47:20 +00:00
28 lines
767 B
TypeScript
28 lines
767 B
TypeScript
import { HassEntities } from "home-assistant-js-websocket";
|
|
import type { GroupEntity } from "../../data/group";
|
|
import { DEFAULT_VIEW_ENTITY_ID } from "../const";
|
|
|
|
// Return an ordered array of available views
|
|
export const extractViews = (entities: HassEntities): GroupEntity[] => {
|
|
const views: GroupEntity[] = [];
|
|
|
|
Object.keys(entities).forEach((entityId) => {
|
|
const entity = entities[entityId];
|
|
if (entity.attributes.view) {
|
|
views.push(entity as GroupEntity);
|
|
}
|
|
});
|
|
|
|
views.sort((view1, view2) => {
|
|
if (view1.entity_id === DEFAULT_VIEW_ENTITY_ID) {
|
|
return -1;
|
|
}
|
|
if (view2.entity_id === DEFAULT_VIEW_ENTITY_ID) {
|
|
return 1;
|
|
}
|
|
return view1.attributes.order - view2.attributes.order;
|
|
});
|
|
|
|
return views;
|
|
};
|