BrianHumlicek / modern-forms-fan-button-row

Home Assistant entity row for Modern Forms 6 speed fans
0 stars 0 forks source link

Custom element doesn't exist: modern-forms-fan-button-row. #1

Open kshunterco opened 10 months ago

kshunterco commented 10 months ago

Hey, first thank you for your work, the lack of responses in the "Lovelace Custom Fan Control Example" thread leads me to believe this is working for people, although who knows.

I just installed this and have properly updated resources, but am still getting the "Custom element doesn't exist" error. I am aware you made this update to account for Polymer being removed from HA, so obviously it's not that!

There are no error or warning messages in the logfile associated with this error...

kshunterco commented 10 months ago

There are no error or warning messages in the logfile associated with this error...

Running NoScript; needed to allow unpkg.com. Works fine. Sorry about that!

kshunterco commented 10 months ago

Final comment - I really didn't like needing to pull the imports from another site, but a little research showed that replacing

import {
    LitElement,
    html,
    css,
} from "https://unpkg.com/lit-element@2.0.1/lit-element.js?module";

with

var LitElement = LitElement || Object.getPrototypeOf(customElements.get("home-assistant-main"));
var html = LitElement.prototype.html;
var css = LitElement.prototype.css;

keeps everything local... Best Kendall

BrianHumlicek commented 10 months ago

The import code was boilerplate from the home assistant developer site. I honestly don't know enough about python to understand what the difference is. If you would care to explain more, I would consider changing it.

https://developers.home-assistant.io/docs/frontend/custom-ui/custom-card/#advanced-example

kshunterco commented 10 months ago

[...] If you would care to explain more, I would consider changing it. [...]

I'm more of a MATLAB / Python / f90 developer so am not exactly sure how globals work in JS, but I'll do my best. Maybe someday someone else will fall into this thread and do a better job 🤣

When I first downloaded your code I opened the issue not realizing that NoScript (Chrome plug-in that prevents JS from running from various sources, in case you're not familiar) wasn't allowing access to unpkg.com - only local access. So I was getting the error described above. When I allowed that script access, it worked.

HOWEVER, the paranoid crazy part of me doesn't like running scripts from other sources especially in a home security setup. So I thought "HA has moved over to Lit, so there must be a local copy of the library with each HA installation"... right? I think? So then if one could perform the import from that local library instead of from unpkg.com, violà! No security hazard and no concerns if for some reason I can't access unpkg.com on any given day. So I Googled for ways to do this and found others attempting (or succeeding) at it:

https://community.home-assistant.io/t/local-availability-on-hass-of-lit-element/93338/ https://github.com/custom-cards/button-card/issues/43

...these examples import from hui-error-entity-row which was removed, so that isn't quite it, but then:

https://community.home-assistant.io/t/custom-dark-sky-animated-weather-card/59816/875?page=66

...shows a way to get the proper classes from home-assistant-main (which I would think should be in every install) so I went with that. Now, why this works, OMG I have no idea. Sorry, I wish I knew because I would enjoy being able to program in JS... not enough time in the day and too much MATLAB / Python work to do...

Best Kendall