lovelace-card-mod: 2025.1.0 beta breaks several fundamental card_mods

My Home Assistant version: 2025.1.0b2

My lovelace configuration method (GUI or yaml): yaml What I am doing:

modding an icon and its color

What I expected to happen:

the mod to be effective (as it has been for years…)

What happened instead:

nothing

Minimal steps to reproduce:

# The least amount of code possible to reproduce my error
          - entity: script.intercom_text_message
            name: Speel bericht
            card_mod:
              style: |
                :host {
                  --card-mod-icon-color:
                    {% set state = states(config.entity) %}
                    {{'var(--alert-color)' if state == 'on' else 'var(--success-color)'}};
                  --card-mod-icon:
                    mdi:{{'stop' if state == 'on' else 'play'}};
                }
# End of code

or even smaller:

          - entity: input_text.message
            name: Bericht
            card_mod:
              style:
                hui-generic-entity-row $: |
                  state-badge {
                    display: none;
                  }

there are many more mods that are not functional anymore, this is a very tight one to start investigating what has changed, I can upload more if required. many of the others involve modding hui-generic-entity-row like this

Error messages from the browser console:

no errors at all

There has been some response in the current Beta channel onDiscord, and Bram said they changed some attributes, but that is about it for now, hope they will get back soon. (it’s Christmas so sure hope everyone is well)

As far as merged PR’s in Frontend, I havent been able to find any relevant change yet that could have caused this wide spread breaking changes in card_mod Sincerely hope others can chime in and help out.

By putting an X in the boxes ([]) below, I indicate that I:

  • Understand that this is a channel for reporting bugs, not a support forum (https://community.home-assistant.io/).

  • Have made sure I am using the latest version of the plugin.

  • Have followed the troubleshooting steps of the “Common Problems” section of https://github.com/thomasloven/hass-config/wiki/Lovelace-Plugins.

  • Understand that leaving one or more boxes unticked or failure to follow the template above may increase the time required to handle my bug-report, or cause it to be closed without further action.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 11
  • Comments: 84 (10 by maintainers)

Commits related to this issue

Most upvoted comments

Feel free to ping me on discord for big things like this if discovered during the beta. I’ve suffered from burnout this fall, so I really haven’t had the energy to keep up, but this didn’t take me two minutes to find once I knew there was a problem…

Thanks to all the people debugging here, too. You were spot on!

so now we found what happened and how this can be mitigated, I guess the only thing keeping this issue from closure is an update by the master @thomasloven himself?

not my habit of tagging anyone, but given this is breaking for 2025.1 upward, the exception seems valid this time

Thomas please have a look?

There were also changes in picture-glance (renderEntity -> _renderEntity). But (at least with patched card-mod) these styles (animation) still work - then hopefully other things do (need more time to check): pg

Similarly - Glance card (renderEntity -> _renderEntity), works OK with patched card-mod: image

Button card (getStateColor -> _getStateColor), works OK with patched card-mod (probably worked fine with an original card-mod as well): image

Imho it was only renderEntity which affected card-mod.

hm, you sure? I see it in this commit

I wrote earlier, missed it somehow when tried to find by Ctrl-F. We are looking at same commit, I am merely at a half of it now))))

One of the possible very-hacky-hacky

Meanwhile users may merely open “card-mod.js” file and replace “renderEntity” with “_renderEntity”, then purge a browser’s cache.

Of course a normal patch is needed for card-mod… As you said, the “renderEntity” may be just ONE example out of many.

Disclaimer - this is what I assume after some quick debugging.

It appears that some of the methods that card_mod hijacks (e.g. patches) have been renamed in HA 2025.1 front-end.

I examined hui-entities-card specifically and mods started working when I changed the name of the patched method from renderEntity to _renderEntity in card-mod’s version of the card (src/patch/hui-entities-card.ts). 🤷

I guess, as a start, someone has to check all the methods in patched versions of UI elements from card-mod (src/patch/*.ts) against the corresponding UI elements from HA front-end.

This commit (linter fixes): https://github.com/home-assistant/frontend/commit/7a12fd285323e25a349f84703c5d74cb4b9fef75

It appears linter wants private method names to start with the underscore because there is a whole lot of changes like this in that commit.

Unfortunately, though, just changing the names of patched methods is not enough - it will stop working for older versions of HA. 🤦

Having the same issue. None of my entity rows with --card-mod-icon-color: or hui-generic-entity-row parameters configured are working in the HA 2025.1.0 beta. No issues with any of the 2024.12.x versions or prior.

I’ve just backed out 2025.1 for this reason and the breakage of auto-backup and Generac. Changing icon colors is something long overdue for inclusion in HA as a core feature.

https://github.com/home-assistant/frontend/pull/23603 will restore the removed attributes to ha-entity-marker (if approved 🤞 )

I’m assuming this is what you need: image

Got it working, the copy didn’t work for me (maybe the original was still also loading) but adding the “_” AND renaming the .GZ on the original worked. Thanks!

@ildar170975 , hm, you sure? I see it in this commit

image

Doesn’t matter - the change has been made. Now - for fixing it.

One of the possible very-hacky-hacky options is changing the behaviour of patch_object to first check whether the method exists. If not, try patching the method with prepended underscore. If that one does not exist as well - just add the method to the patched class and hope for the best.

Now, this is a very quick and dirty fix - obviously - so I guess not all problems can be solved by this.

Something in the lines of

export const patch_object = (obj, patch) => {
  if (!obj) return;
  const orig = Object.getOwnPropertyDescriptors(obj);
  console.debug("CardMod orig methods", {orig, patch});
  for (const method in Object.getOwnPropertyDescriptors(patch.prototype)) {
    if (orig[method]) patch_method(obj, method, patch.prototype[method]);
    else if (orig[`_${method}`]) patch_method(obj, `_${method}`, patch.prototype[method]);
    else {
      console.debug(`CardMod method ${method} of ${obj.constructor.name} not found. Injecting patched version.`);
      patch_method(obj, method, patch.prototype[method]);
    }
  }
};

you have 2 version of card_mod…

Thanks for the quick response, I removed the UI lovelace minimalist HACS add-on, restarted everything, so only one card_mod shows but still on the mushroom chips card the formatting issue remains

Remove

thanks Thomas, all the best, and stay healthy first!

Fine. Just have it said that everyone should ideally follow the authors advice and load card-mod via the Frontend config like I posted and like you yourself linked the documentation

People posting ‘it doesn’t work for me’ is a well known phenomenon here and elsewhere. Mostly because not following advice, documentation or simply wrong configs. And cache. Cache is a well known offender. Especially when using the HACS method……

taking temporary files outside of HACS is a more reliable method of testing than any other.

But sure, I am glad people get it to work how each and everyone manages in their own setting.

Worked with GZ renamed

Edititng the original js file, renaming the gz-file to gz.old and then reload without cache should work as well. IMHO Less to edit and change.

because of another patch in the map card elements.

Yes, and this cannot be fixed by card-mod (hope to be wrong!!!). The ha-entity-marker has no it’s entity-id attribute exposed in DOM: image

https://github.com/home-assistant/frontend/pull/23247/files image

Meanwhile users may merely open “card-mod.js” file and replace “renderEntity” with “_renderEntity”, then purge a browser’s cache.

I can confirm this to restore most issues I observed!

this is back in the main entities ( and not only in the fold):

Scherm­afbeelding 2025-01-04 om 22 17 08

my HA card has its background set correctly again:

Scherm­afbeelding 2025-01-04 om 22 19 19

text-input-row can be without icon

Scherm­afbeelding 2025-01-04 om 22 20 47

and all of my folds are back scrolling!!

Id say this is the fix we’ve been waiting for

to prevent having ti fight with the HACS install, just add it to your www folder in anther folder and link that in the config:

frontend:
  extra_module_url:
# https://github.com/thomasloven/lovelace-card-mod?tab=readme-ov-file#performance-improvements
    - /local/resources/card-mod/card-mod.js  # <----- this is a copy with the single edit
#     - /hacsfiles/lovelace-card-mod/card-mod.js

If a method for testing methods (like yours) would be provided in card-mod - it will hopefully help in case of that “xxx -> _xxx” change. As for other things - let’s see.

I completed my check of that commit. Now testing EVERY card with renamed methods.

Tested Entity card: hui-entity-card.ts: getStateColor was renamed Styles seem to work OK.

Hello, same problem here. Color stopped working in Core 2025.1.0, Frontend 20250103.0

  • entity: binary_sensor.shelly_sensor_portao_window name: Portão icon: mdi:gate card_mod: style: | :host { {% if states(‘binary_sensor.shelly_sensor_portao_window’) == ‘off’ %} –paper-item-icon-color: green; color: green; {% elif states(‘binary_sensor.shelly_sensor_portao_window’) == ‘on’ %} –paper-item-icon-color: red; color: red; {% endif %} }