DavidFW1960 / bom-weather-card

Custom Animated Weather Card for any weather provider
Apache License 2.0
162 stars 37 forks source link

Watch this._hass & .config, exit render if not set #74

Closed manisar2 closed 2 years ago

manisar2 commented 2 years ago

Opening this PR for issue #73 described below:


I'm seeing that mostly render() method is called before set hass(hass). This means that current() (called from render) does not have this._hass to work upon, so it throws an error, and prevents the rendering of the subsequent html in render().

On making these two changes, my testing has shown good results.

  1. In the beginning of render():
    if (!this.config || !this._hass) return html``;  // checking .config is also not a bad idea
  2. With above, we want render() to be called again when set hass(hass) is called. This can be done by watching this._hass property, and the following getter will do that:
    static get properties() {
      return {
       _hass: {},
       config: {},
      };
    }