1+ import { getAreasFloorHierarchy } from "../common/areas/areas-floor-hierarchy" ;
12import { computeAreaName } from "../common/entity/compute_area_name" ;
23import { computeDomain } from "../common/entity/compute_domain" ;
34import { computeFloorName } from "../common/entity/compute_floor_name" ;
@@ -12,11 +13,7 @@ import {
1213} from "./device_registry" ;
1314import type { HaEntityPickerEntityFilterFunc } from "./entity" ;
1415import type { EntityRegistryDisplayEntry } from "./entity_registry" ;
15- import {
16- floorCompare ,
17- getFloorAreaLookup ,
18- type FloorRegistryEntry ,
19- } from "./floor_registry" ;
16+ import type { FloorRegistryEntry } from "./floor_registry" ;
2017
2118export interface FloorComboBoxItem extends PickerComboBoxItem {
2219 type : "floor" | "area" ;
@@ -182,68 +179,59 @@ export const getAreasAndFloors = (
182179 ) ;
183180 }
184181
185- const floorAreaLookup = getFloorAreaLookup ( outputAreas ) ;
186- const unassignedAreas = Object . values ( outputAreas ) . filter (
187- ( area ) => ! area . floor_id || ! floorAreaLookup [ area . floor_id ]
188- ) ;
189-
190- const compare = floorCompare ( haFloors ) ;
191-
192- // @ts -ignore
193- const floorAreaEntries : [
194- FloorRegistryEntry | undefined ,
195- AreaRegistryEntry [ ] ,
196- ] [ ] = Object . entries ( floorAreaLookup )
197- . map ( ( [ floorId , floorAreas ] ) => {
198- const floor = floors . find ( ( fl ) => fl . floor_id === floorId ) ! ;
199- return [ floor , floorAreas ] as const ;
200- } )
201- . sort ( ( [ floorA ] , [ floorB ] ) => compare ( floorA . floor_id , floorB . floor_id ) ) ;
182+ const hierarchy = getAreasFloorHierarchy ( floors , outputAreas ) ;
202183
203184 const items : FloorComboBoxItem [ ] = [ ] ;
204185
205- floorAreaEntries . forEach ( ( [ floor , floorAreas ] ) => {
206- if ( floor ) {
207- const floorName = computeFloorName ( floor ) ;
186+ hierarchy . floors . forEach ( ( f ) => {
187+ const floor = haFloors [ f . id ] ;
188+ const floorAreas = f . areas . map ( ( areaId ) => haAreas [ areaId ] ) ;
208189
209- const areaSearchLabels = floorAreas
210- . map ( ( area ) => {
211- const areaName = computeAreaName ( area ) || area . area_id ;
212- return [ area . area_id , areaName , ...area . aliases ] ;
213- } )
214- . flat ( ) ;
190+ const floorName = computeFloorName ( floor ) ;
191+
192+ const areaSearchLabels = floorAreas
193+ . map ( ( area ) => {
194+ const areaName = computeAreaName ( area ) ;
195+ return [ area . area_id , ...( areaName ? [ areaName ] : [ ] ) , ...area . aliases ] ;
196+ } )
197+ . flat ( ) ;
198+
199+ items . push ( {
200+ id : formatId ( { id : floor . floor_id , type : "floor" } ) ,
201+ type : "floor" ,
202+ primary : floorName ,
203+ floor : floor ,
204+ icon : floor . icon || undefined ,
205+ search_labels : [
206+ floor . floor_id ,
207+ floorName ,
208+ ...floor . aliases ,
209+ ...areaSearchLabels ,
210+ ] ,
211+ } ) ;
215212
216- items . push ( {
217- id : formatId ( { id : floor . floor_id , type : "floor" } ) ,
218- type : "floor" ,
219- primary : floorName ,
220- floor : floor ,
221- icon : floor . icon || undefined ,
222- search_labels : [
223- floor . floor_id ,
224- floorName ,
225- ...floor . aliases ,
226- ...areaSearchLabels ,
227- ] ,
228- } ) ;
229- }
230213 items . push (
231214 ...floorAreas . map ( ( area ) => {
232- const areaName = computeAreaName ( area ) || area . area_id ;
215+ const areaName = computeAreaName ( area ) ;
233216 return {
234217 id : formatId ( { id : area . area_id , type : "area" } ) ,
235218 type : "area" as const ,
236- primary : areaName ,
219+ primary : areaName || area . area_id ,
237220 area : area ,
238221 icon : area . icon || undefined ,
239- search_labels : [ area . area_id , areaName , ...area . aliases ] ,
222+ search_labels : [
223+ area . area_id ,
224+ ...( areaName ? [ areaName ] : [ ] ) ,
225+ ...area . aliases ,
226+ ] ,
240227 } ;
241228 } )
242229 ) ;
243230 } ) ;
244231
245232 items . push (
246- ...unassignedAreas . map ( ( area ) => {
233+ ...hierarchy . areas . map ( ( areaId ) => {
234+ const area = haAreas [ areaId ] ;
247235 const areaName = computeAreaName ( area ) || area . area_id ;
248236 return {
249237 id : formatId ( { id : area . area_id , type : "area" } ) ,
0 commit comments