@@ -665,29 +665,35 @@ export class FloorplanElement extends LitElement {
665665 entityId : string ,
666666 ruleInfo : FloorplanRuleInfo ,
667667 useCache : boolean
668- ) : Promise < SVGGraphicsElement > {
669- const isSvg =
668+ ) : Promise < SVGGraphicsElement | undefined > {
669+ try {
670+ const isSvg =
670671 imageUrl . toLowerCase ( ) . includes ( '.svg' ) ||
671672 svgElementInfo . svgElement . nodeName === 'svg' ||
672673 svgElementInfo . svgElement . querySelector ( 'svg' ) ;
673674
674- if ( isSvg ) {
675- return await this . loadSvgImage (
676- imageUrl ,
677- svgElementInfo ,
678- entityId ,
679- ruleInfo ,
680- useCache
681- ) ;
682- } else {
683- return await this . loadBitmapImage (
684- imageUrl ,
685- svgElementInfo ,
686- entityId ,
687- ruleInfo ,
688- useCache
689- ) ;
675+ if ( isSvg ) {
676+ return await this . loadSvgImage (
677+ imageUrl ,
678+ svgElementInfo ,
679+ entityId ,
680+ ruleInfo ,
681+ useCache
682+ ) ;
683+ } else {
684+ return await this . loadBitmapImage (
685+ imageUrl ,
686+ svgElementInfo ,
687+ entityId ,
688+ ruleInfo ,
689+ useCache
690+ ) ;
691+ }
692+ }
693+ catch ( e ) {
694+ this . logError ( 'IMAGE' , `Could not initialize image: ${ imageUrl } , error: ${ e } ` ) ;
690695 }
696+ return ;
691697 }
692698
693699 async loadBitmapImage (
@@ -1184,7 +1190,7 @@ export class FloorplanElement extends LitElement {
11841190 elementIds = elementIds . concat (
11851191 this . evaluate ( rule . element , entityId , undefined ) as string
11861192 ) ;
1187- else if ( rule . element !== null && rule . element !== undefined ) elementIds = elementIds . concat ( entityId ) ;
1193+ else if ( rule . element !== null ) elementIds = elementIds . concat ( entityId ) ;
11881194
11891195 // Do not add target entity "*"
11901196 if ( entityId && entityId === "*" ) continue ;
@@ -1296,7 +1302,7 @@ export class FloorplanElement extends LitElement {
12961302 ) ;
12971303 }
12981304
1299- if ( ruleInfo . rule . tap_action || ruleInfo . rule . double_tap_action ) {
1305+ if ( ruleInfo ? .rule ? .tap_action || ruleInfo ? .rule ? .double_tap_action ) {
13001306 const singleTapAction = ruleInfo . rule . tap_action
13011307 ? this . getActionConfigs ( ruleInfo . rule . tap_action )
13021308 : false ;
@@ -1345,7 +1351,7 @@ export class FloorplanElement extends LitElement {
13451351 Utils . addClass ( element , `floorplan-click${ isParent ? '' : '-child' } ` ) ; // mark the element as being processed by floorplan
13461352 }
13471353
1348- if ( ruleInfo . rule . hold_action ) {
1354+ if ( ruleInfo ? .rule ? .hold_action ) {
13491355 const actions = this . getActionConfigs ( ruleInfo . rule . hold_action ) ;
13501356 const context = new FloorplanClickContext (
13511357 this ,
@@ -2191,8 +2197,8 @@ export class FloorplanElement extends LitElement {
21912197 case 'image_set' :
21922198 let nestedSvgElementRef = undefined ;
21932199
2194- // If rule does not have a parent element ref, we'll need to check if element is part of actionConfig.service_data
2195- if ( ! svgElementInfo && typeof actionConfig ?. service_data === "object" ) {
2200+ // We'll prioritize the element from the service data, if it's provided
2201+ if ( typeof actionConfig ?. service_data === "object" ) {
21962202 // We do not support elements, as nested service_data
21972203 if ( actionConfig ?. service_data ?. elements ) {
21982204 this . logError (
@@ -2223,29 +2229,49 @@ export class FloorplanElement extends LitElement {
22232229
22242230 if ( svg . length < 1 ) {
22252231 this . logError (
2226- 'CONFIG' , 'No valid element found in service data.'
2227- )
2232+ 'CONFIG' ,
2233+ 'Could not locate the specified element from the service data within the SVG. Please ensure the element ID is correct and exists in the SVG.'
2234+ ) ;
22282235 break ;
22292236 }
22302237
22312238 // Use the first element found
22322239 svgElementInfo = this . generateSvgElementInfo ( svg [ 0 ] ) ;
22332240 }
22342241
2235- if ( svgElementInfo && ruleInfo ) {
2242+ if ( svgElementInfo && ( ruleInfo || actionConfig ?. _is_internal_action_scope ) ) {
22362243 serviceData = this . getServiceData (
22372244 actionConfig ,
22382245 entityId ,
22392246 svgElementInfo ?. svgElement
22402247 ) ;
22412248
2242- imageUrl =
2243- typeof serviceData === 'string'
2244- ? serviceData
2245- : ( serviceData . image as string ) ;
2249+ let imageUrl ;
2250+ if ( typeof serviceData !== undefined ) {
2251+ // Allow internal actions to use the image from included service data
2252+ if ( actionConfig && actionConfig . _is_internal_action_scope ) {
2253+ serviceData = actionConfig ?. service_data ;
2254+ const data = actionConfig ?. service_data as Record < string , unknown > ;
2255+ if ( data ?. image !== null ) {
2256+ if ( typeof data ?. image === "string" ) imageUrl = data ?. image as string ;
2257+ if ( typeof data ?. image === "object" ) {
2258+ const image = data ?. image as FloorplanImageConfig ;
2259+ if ( 'location' in image && typeof image . location === "string" ) imageUrl = image . location ;
2260+ }
2261+ }
2262+ }
2263+ else if ( typeof serviceData === "string" ) {
2264+ imageUrl = serviceData as string ;
2265+ } else if ( typeof serviceData === "object" ) {
2266+ if ( typeof serviceData ?. image === "string" ) imageUrl = serviceData ?. image as string ;
2267+ if ( serviceData ?. image !== null && typeof serviceData ?. image === "object" && "location" in serviceData ?. image && typeof serviceData . image . location === "string" ) {
2268+ imageUrl = serviceData . image . location ;
2269+ }
2270+ }
2271+ }
22462272
22472273 imageRefreshInterval =
2248- typeof serviceData === 'object'
2274+ ! actionConfig ?. _is_internal_action_scope && typeof serviceData === 'object'
22492275 ? ( serviceData . image_refresh_interval as number )
22502276 : 0 ;
22512277
@@ -2258,11 +2284,11 @@ export class FloorplanElement extends LitElement {
22582284 : true ; // use cache by default
22592285 }
22602286
2261- if ( ruleInfo . imageLoader ) {
2287+ if ( ruleInfo ? .imageLoader ) {
22622288 clearInterval ( ruleInfo . imageLoader ) ; // cancel any previous image loading for this rule
22632289 }
22642290
2265- if ( imageRefreshInterval ) {
2291+ if ( imageRefreshInterval && ruleInfo && ! actionConfig ?. _is_internal_action_scope ) {
22662292 ruleInfo . imageLoader = setInterval (
22672293 this . loadImage . bind ( this ) ,
22682294 imageRefreshInterval * 1000 ,
@@ -2274,6 +2300,8 @@ export class FloorplanElement extends LitElement {
22742300 ) ;
22752301 }
22762302
2303+ if ( ! imageUrl ) break ;
2304+
22772305 this . loadImage (
22782306 imageUrl ,
22792307 svgElementInfo ,
@@ -2456,6 +2484,7 @@ export class FloorplanElement extends LitElement {
24562484 const customEvent = event as CustomEvent < FloorplanEventActionCallDetail > ;
24572485 const { actionConfig, entityId, svgElementInfo, ruleInfo } = customEvent . detail ;
24582486
2487+ actionConfig . _is_internal_action_scope = true ;
24592488 this . handleActions ( actionConfig , entityId , svgElementInfo , ruleInfo ) ;
24602489
24612490 //this.callService(actionConfig, entityId, svgElementInfo, ruleInfo);
0 commit comments