Skip to content

Commit

Permalink
fixed fast changing quotes and CSS
Browse files Browse the repository at this point in the history
- fixed fast changing quotes using PR #41 in air-visual-card. But now it only shows one quote all the time
- added border-radius CSS variable so card-mod should now work when setting border-radius
  • Loading branch information
dnguyen800 committed Sep 29, 2021
1 parent 097189b commit 55f6c91
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion dist/quote-of-the-day-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
// Feedparser data loads each RSS feed data entry as an HA entity's attribute. The name of the attribute is the name of the author, like 'Oscar Wilde'.
// The quote's data is stored as a dictionary under key 'Oscar Wilde'. Access an entry by hass.states[config.entity].attributes[author name][column name]


let oldStates = {}


class QuoteOfTheDayCard extends HTMLElement {

constructor() {
super();
oldStates = {}
this.attachShadow({ mode: 'open' });
}

Expand All @@ -26,6 +31,8 @@ class QuoteOfTheDayCard extends HTMLElement {
style.textContent = `
ha-card {
/* sample css */
ha-card-box-shadow: var(--box-shadow);
border-radius: var(--border-radius);
}
body {
Expand Down Expand Up @@ -59,6 +66,8 @@ class QuoteOfTheDayCard extends HTMLElement {
margin-right: auto;
width: 100%;
height: auto;
ha-card-box-shadow: var(--box-shadow);
border-radius: var(--border-radius);
}
/*=== Trigger ===*/
Expand Down Expand Up @@ -117,11 +126,32 @@ class QuoteOfTheDayCard extends HTMLElement {
this._config = cardConfig;
}


// Helper method that checks if there are any changes to the states before it refreshes the card. See @swampen PR #41 in air-visual-card
shouldNotUpdate(config, hass) {
let clone = JSON.parse(JSON.stringify(config))
// Here, delete any config attribute that should not be checked for updates
delete clone["image"]
delete clone["feed_attribute"]
delete clone["type"]
let states = {}
for (let entity of Object.values(clone)) {
states[entity] = hass.states[entity]
}
if (JSON.stringify(oldStates) === JSON.stringify(states)) {
return true
}
oldStates = states
return false
}

set hass(hass) {
const config = this._config;
const root = this.shadowRoot;
const card = root.lastChild;
if (this.shouldNotUpdate(config, hass)) {
return
}

this.myhass = hass;
let card_content = '';
let quote_content = ``;
Expand Down

0 comments on commit 55f6c91

Please sign in to comment.