custom-cards / secondaryinfo-entity-row

Custom entity row for HomeAssistant, providing additional types of data to be displayed in the secondary info area of the Lovelace Entities card
172 stars 15 forks source link

can't find card-tools (which shouldn't be necessary) #32

Closed Mariusthvdb closed 4 years ago

Mariusthvdb commented 4 years ago

while Thomas Loven explicitly says this here

Just for the record - the only good reason to have card-tools installed is because another card tells you to. None of my cards do, and if you find one that does, you should really let the maintainer know that there are better ways to get that functionality nowadays. I'll gladly help with the transition.

please contact Thomas and try to fix this?

Schermafbeelding 2020-08-06 om 23 38 29
snakuzzo commented 4 years ago

Any news about this issue ?

MizterB commented 4 years ago

I don't believe the above error is related to Thomas' comment. You need his latest card-tools installed to use this card, as described in the README. The error indicates that it isn't installed (or is not installed correctly).

While he mentions that card-tools can be integrated directly into this card instead of being an external dependency, I don't have the time or expertise to make such a change right now. Of course, I'll gladly take a PR from anyone willing to help.

At the same time, I don't personally expect to make significant changes to this card going forward. It has clearly served it's purpose, but frankly has been superseded by the more flexible template-entity-row.

Mariusthvdb commented 4 years ago

HI MizterB

there's a big difference (and reason for me to use your card) with template-entity-row, and that is your card can show the toggle on an switch, while the Ter card shows the state.:

Schermafbeelding 2020-08-13 om 17 35 37
          - type: custom:secondaryinfo-entity-row
            entity: switch.boiler_bijkeuken
            state_color: true
            secondary_info: 'Actueel verbruik: [[ sensor.boiler_bijkeuken_actueel ]] watt'

          - type: custom:template-entity-row
            entity: switch.boiler_bijkeuken
            active: >
              {{is_state(config.entity,'on')}}
            secondary: >
              Actueel verbruik: {{states('sensor.boiler_bijkeuken_actueel')}} watt

so, it would be very nice indeed if your card would incorporate the card-tools.... though I fully appreciate your remarks about time and expertise. Maybe Thomas can lend a hand, as he in fact suggests is the post himself?

snakuzzo commented 4 years ago

anyway...I fixed upgrading card-tools to latest version (11)

Mariusthvdb commented 4 years ago

Hey @MizterB,

just found another possibility your card currently offers over the other available row templaters like template-entity-row and multiple-entity-row: It keeps the slider when using a secondary line on an input_number.

This alone was reason enough to re-install the card, so thanks for making that possible.

Only gripe was, that because of that, O also had to re-install the resource card-tools....

Wouldn't you be able to contact Thomas, on how to prevent that necessity? He offered assistance after all, and it would be very nice if your card wouldn't be just about the only one needing the card-tools explicitly loaded from the resources.

hope you can have a look.

here's what I posted in the community on this: https://community.home-assistant.io/t/input-number-with-secondary-line-how-to-keep-the-slider/226645

Mariusthvdb commented 3 years ago

Thomas helped me out (instructed me.... ;-) ) and this results in a resource not needing the external card-tools any more:

console.info(
  `%c SECONDARYINFO-ENTITY-ROW  \n%c  Version 0.6 no card-tools  `,
  "color: orange; font-weight: bold; background: black",
  "color: white; font-weight: bold; background: dimgray",
 );

var Lit = Lit || Object.getPrototypeOf(customElements.get("ha-panel-lovelace") || customElements.get('hui-view'));
var html = Lit.prototype.html;

const helpers = await window.loadCardHelpers();

export async function parseTemplate(hass, str, specialData = {}) {
  if (typeof(specialData === "string")) specialData = {};
    specialData = Object.assign({
      user: hass.user.name,
      hash: location.hash.substr(1) || ' ',
    },
    specialData);

    for (var k in specialData) {
      var re = new RegExp(`\\{${k}\\}`, "g");
      str = str.replace(re, specialData[k]);
    }

    return hass.callApi("POST", "template", {template: str});
};

class SecondaryInfoEntityRowCard extends Lit {

        render() {
            return html`
                ${this._wrappedElement}
            `;
        }

        setConfig(config) {
            this._config = config;
            this._wrappedElement = this._createElement(config);
            this.requestUpdate();
        }

        set hass(hass) {
            this._hass = hass;
            this._stateObj = this._config.entity in hass.states ? hass.states[this._config.entity] : null;
            this._updateElement(this._wrappedElement, hass);
        }

        _createElement(config) {
            // Override the custom row type in order to create the 'standard' row for this entity
            let defaultRowConfig = Object.assign({}, config);
            delete defaultRowConfig.type;
            const element = helpers.createRowElement(defaultRowConfig);
            return element;
        }

        async _updateElement(wrappedElement, hass) {
            if (!wrappedElement) return;

            this._wrappedElement.hass = hass;
            await this._wrappedElement.updateComplete;
            await this._wrappedElement.shadowRoot.querySelector("hui-generic-entity-row");
            let secondaryInfoDiv = this._wrappedElement.shadowRoot.querySelector("hui-generic-entity-row").shadowRoot.querySelector(".secondary");
            if (secondaryInfoDiv && this._config.secondary_info) {
                let text;
                if (this._config.secondary_info.includes('{{') || this._config.secondary_info.includes('{%')) {
                    text = await parseTemplate(hass, this._config.secondary_info, {entity: this._config.entity})
                } else {
                    text = parseTemplate(this._config.secondary_info, {entity: this._config.entity});
                }
                secondaryInfoDiv.innerHTML = text;
            }
        }
    }

customElements.define('secondaryinfo-entity-row', SecondaryInfoEntityRowCard);