@@ -454,64 +454,34 @@ class WebServer {
454454 try {
455455 const http = require ( 'http' ) ;
456456 const data = await new Promise ( ( resolve ) => {
457- const req = http . request ( 'http://supervisor/core/api/areas' , {
458- method : 'GET' ,
457+ const tmpl = '{{ areas() | map("area_name") | list | to_json }}' ;
458+ const postBody = JSON . stringify ( { template : tmpl } ) ;
459+ const req = http . request ( 'http://supervisor/core/api/template' , {
460+ method : 'POST' ,
459461 headers : {
460462 'Authorization' : `Bearer ${ supervisorToken } ` ,
461- 'Content-Type' : 'application/json'
463+ 'Content-Type' : 'application/json' ,
464+ 'Content-Length' : Buffer . byteLength ( postBody )
462465 } ,
463466 timeout : 5000
464467 } , ( resp ) => {
465468 let body = '' ;
466469 resp . on ( 'data' , ( chunk ) => { body += chunk ; } ) ;
467470 resp . on ( 'end' , ( ) => {
468- this . logger . info ( `Area API HTTP ${ resp . statusCode } , body length: ${ body . length } , preview: ${ body . slice ( 0 , 200 ) } ` ) ;
471+ this . logger . info ( `Area API HTTP ${ resp . statusCode } , body length: ${ body . length } , preview: ${ body . slice ( 0 , 300 ) } ` ) ;
469472 try { resolve ( JSON . parse ( body ) ) ; } catch { resolve ( null ) ; }
470473 } ) ;
471474 } ) ;
472475 req . on ( 'error' , ( e ) => { this . logger . warn ( 'Area API request error:' , e . message ) ; resolve ( null ) ; } ) ;
473476 req . on ( 'timeout' , ( ) => { this . logger . warn ( 'Area API request timeout' ) ; req . destroy ( ) ; resolve ( null ) ; } ) ;
477+ req . write ( postBody ) ;
474478 req . end ( ) ;
475479 } ) ;
476- this . logger . info ( `Area registry response: type=${ typeof data } , isArray=${ Array . isArray ( data ) } , length=${ Array . isArray ( data ) ? data . length : 'n/a' } , preview= ${ JSON . stringify ( data ) . slice ( 0 , 300 ) } ` ) ;
480+ this . logger . info ( `Area template response: type=${ typeof data } , isArray=${ Array . isArray ( data ) } , length=${ Array . isArray ( data ) ? data . length : 'n/a' } ` ) ;
477481 if ( Array . isArray ( data ) ) {
478- // Fetch floors to resolve floor_id → name
479- const floorMap = { } ;
480- try {
481- const floorData = await new Promise ( ( resolve2 ) => {
482- const fReq = http . request ( 'http://supervisor/core/api/config/floor_registry/list' , {
483- method : 'POST' ,
484- headers : {
485- 'Authorization' : `Bearer ${ supervisorToken } ` ,
486- 'Content-Type' : 'application/json'
487- } ,
488- timeout : 5000
489- } , ( fResp ) => {
490- let fBody = '' ;
491- fResp . on ( 'data' , ( chunk ) => { fBody += chunk ; } ) ;
492- fResp . on ( 'end' , ( ) => {
493- try { resolve2 ( JSON . parse ( fBody ) ) ; } catch { resolve2 ( null ) ; }
494- } ) ;
495- } ) ;
496- fReq . on ( 'error' , ( ) => resolve2 ( null ) ) ;
497- fReq . on ( 'timeout' , ( ) => { fReq . destroy ( ) ; resolve2 ( null ) ; } ) ;
498- fReq . end ( ) ;
499- } ) ;
500- if ( Array . isArray ( floorData ) ) {
501- for ( const f of floorData ) {
502- if ( f . floor_id && f . name ) floorMap [ f . floor_id ] = f . name ;
503- }
504- }
505- } catch { /* floors not available */ }
506-
507- for ( const area of data ) {
508- if ( area . name ) {
509- const entry = { id : area . area_id , name : area . name } ;
510- if ( area . floor_id && floorMap [ area . floor_id ] ) {
511- entry . floor = floorMap [ area . floor_id ] ;
512- }
513- if ( area . icon ) entry . icon = area . icon ;
514- haAreas . push ( entry ) ;
482+ for ( const name of data ) {
483+ if ( typeof name === 'string' && name ) {
484+ haAreas . push ( { name, source : 'homeassistant' } ) ;
515485 }
516486 }
517487 this . _haAreasCache = haAreas ;
@@ -530,10 +500,7 @@ class WebServer {
530500 const key = ha . name . toLowerCase ( ) ;
531501 if ( ! seen . has ( key ) ) {
532502 seen . add ( key ) ;
533- const entry = { name : ha . name , source : 'homeassistant' } ;
534- if ( ha . floor ) entry . floor = ha . floor ;
535- if ( ha . icon ) entry . icon = ha . icon ;
536- merged . push ( entry ) ;
503+ merged . push ( { name : ha . name , source : 'homeassistant' } ) ;
537504 }
538505 }
539506 for ( const name of labelAreas ) {
0 commit comments