@@ -178,13 +178,19 @@ const generateActionYaml = (
178178) : string => {
179179 let yaml = ` action: ${ actionType } \n` ;
180180
181- if ( actionType === 'call-service' && actionData ) {
181+ if ( ( actionType === 'call-service' || actionType === 'perform-action' ) && actionData ) {
182182 try {
183183 const data = JSON . parse ( actionData ) ;
184- yaml += ` service: ${ data . service || '' } \n` ;
185- if ( data . service_data ) {
186- yaml += ` service_data:\n` ;
187- Object . entries ( data . service_data ) . forEach ( ( [ key , value ] ) => {
184+ // perform-action uses perform_action key; call-service uses service key
185+ if ( actionType === 'perform-action' ) {
186+ yaml += ` perform_action: ${ data . service || data . perform_action || '' } \n` ;
187+ } else {
188+ yaml += ` service: ${ data . service || '' } \n` ;
189+ }
190+ if ( data . service_data || data . data ) {
191+ const serviceData = data . service_data || data . data ;
192+ yaml += actionType === 'perform-action' ? ` data:\n` : ` service_data:\n` ;
193+ Object . entries ( serviceData ) . forEach ( ( [ key , value ] ) => {
188194 yaml += ` ${ key } : ${ JSON . stringify ( value ) } \n` ;
189195 } ) ;
190196 }
@@ -276,12 +282,13 @@ export const generateYaml = (config: ButtonConfig): string => {
276282 // --- Base Card Styles ---
277283 const cardStyles = [
278284 config . height !== 'auto' ? `height: ${ config . height } ` : null ,
279- config . aspectRatio ? ` aspect-ratio: ${ config . aspectRatio } ` : null ,
285+ // aspect-ratio is already emitted as a top-level YAML property; omit from styles.card
280286 gradientCSS ? gradientCSS : ( bgColor ? `background-color: ${ bgColor } ` : null ) ,
281287 config . cardOpacity < 100 ? `opacity: ${ config . cardOpacity / 100 } ` : null ,
282288 `border-radius: ${ config . borderRadius } ` ,
283289 `padding: ${ config . padding } ` ,
284- `color: ${ config . color } ` ,
290+ // Only emit color in styles.card when not using color:auto (which is a top-level override)
291+ ! config . colorAuto ? `color: ${ config . color } ` : null ,
285292 // Use custom font if specified, otherwise use fontFamily dropdown
286293 ( config . customFontName && config . customFontUrl )
287294 ? `font-family: '${ config . customFontName } ', sans-serif`
@@ -346,7 +353,8 @@ export const generateYaml = (config: ButtonConfig): string => {
346353 if ( config . nameTemplate ) {
347354 yaml += `name: ${ config . nameTemplate } \n` ;
348355 } else if ( config . name ) {
349- yaml += `name: ${ config . name } \n` ;
356+ // Quote the name to handle colons, hashes and other YAML special characters
357+ yaml += `name: "${ config . name . replace ( / \\ / g, '\\\\' ) . replace ( / " / g, '\\"' ) } "\n` ;
350358 }
351359
352360 if ( config . iconTemplate ) {
@@ -407,9 +415,9 @@ export const generateYaml = (config: ButtonConfig): string => {
407415 const showState = hasEntity ? config . showState : false ;
408416 const showLastChanged = hasEntity ? config . showLastChanged : false ;
409417
410- // Only output show options that are true
411- if ( config . showName ) yaml += `show_name: true \n` ;
412- if ( config . showIcon ) yaml += `show_icon: true \n` ;
418+ // show_name/show_icon default to true in button-card — only emit when overriding to false
419+ if ( ! config . showName ) yaml += `show_name: false \n` ;
420+ if ( ! config . showIcon ) yaml += `show_icon: false \n` ;
413421 if ( showState ) yaml += `show_state: true\n` ;
414422 if ( showLabel ) yaml += `show_label: true\n` ;
415423 if ( showEntityPicture ) yaml += `show_entity_picture: true\n` ;
@@ -1334,7 +1342,10 @@ ${stateIconStyles.map(s => ` - ${formatStyleForYaml(s)}`).join('\n')}` :
13341342 conditionalCardStyles . push ( gradientBg ) ;
13351343 }
13361344 } else if ( stateStyle . backgroundColor ) {
1337- conditionalCardStyles . push ( `background-color: ${ stateStyle . backgroundColor } ` ) ;
1345+ // Apply backgroundColorOpacity if set to something other than full opacity
1346+ const bgOpacity = stateStyle . backgroundColorOpacity !== undefined ? stateStyle . backgroundColorOpacity : 100 ;
1347+ const bgValue = bgOpacity < 100 ? hexToRgba ( stateStyle . backgroundColor , bgOpacity ) : stateStyle . backgroundColor ;
1348+ conditionalCardStyles . push ( `background-color: ${ bgValue } ` ) ;
13381349 }
13391350 if ( stateStyle . borderColor ) {
13401351 conditionalCardStyles . push ( `border-color: ${ stateStyle . borderColor } ` ) ;
0 commit comments