Skip to content

Commit

Permalink
Merge pull request #36 from k3a/fix-hass-undefined
Browse files Browse the repository at this point in the history
Set initial URL after a brief delay to avoid this.hass being undefined
  • Loading branch information
dimagoltsman authored Sep 9, 2024
2 parents e207d2e + 592e5b2 commit f159724
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions dist/refreshable-picture-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,28 @@ class ResfeshablePictureCard extends LitElement {

connectedCallback() {
super.connectedCallback?.();

const refreshTime = (this.config.refresh_interval || 30) * 1000;
clearInterval(this._refreshInterval);

if(this._refreshInterval) {
clearInterval(this._refreshInterval);
}
this._refreshInterval = setInterval(
() => (this.pictureUrl = this._getTimestampedUrl()),
refreshTime
);
this.pictureUrl = this._getTimestampedUrl();

// calling it after 10 ms ensures this.hass will be set
setTimeout(
() => (this.pictureUrl = this._getTimestampedUrl()),
10
);
}

disconnectedCallback() {
super.disconnectedCallback?.();
if (this._refreshInterval) {
clearInterval(this._refreshInterval);
this._refreshInterval = undefined;
}
}

Expand Down

0 comments on commit f159724

Please sign in to comment.