Skip to content

Commit

Permalink
Clear cache on refresh of page or config change and calendar_time_for…
Browse files Browse the repository at this point in the history
…mat config setting
  • Loading branch information
gadgetchnnel committed Jun 24, 2021
1 parent 22eaa14 commit 5e81402
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ If this is set, it is used as the key for cacheing the feed in Local Storage, ot
### calendars (optional)
This is a list of calendar entities you want events to display for in your feed.

### calendar_time_format (optional, defaults to relative, added in 0.6.2)
How the calendar event timestamp should be formatted.
Valid values are: relative, date, time and datetime.

### calendar_days_back (optional, defaults to 0, added in 0.3.5b2)
The number of days before the current day to include calendar events for in the feed

Expand Down
14 changes: 7 additions & 7 deletions lovelace-home-feed-card.js

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ class HomeFeedCard extends LitElement {
return this._config.card_id ? this._config.card_id : this.pageId + this._config.title;
}

get editMode() {
let parentNodeName = this.parentElement && this.parentElement.nodeName;
return parentNodeName == "HUI-CARD-PREVIEW";
}

clearCache() {
localStorage.removeItem('home-feed-card-events' + this.cacheId);
localStorage.removeItem('home-feed-card-eventsLastUpdate' + this.cacheId);
Expand All @@ -258,6 +263,11 @@ class HomeFeedCard extends LitElement {
this.calendars = this._config.calendars;
this.oldStates = {};

if(!this.editMode)
{
console.log("Clearing Cache");
this.clearCache();
}
setTimeout(() => this.buildIfReady(), 10);
}

Expand Down Expand Up @@ -531,7 +541,7 @@ class HomeFeedCard extends LitElement {
let calendarObject = this._hass.states[i.calendar];
if(!calendarObject) return []; // If calendar entity does not exist return empty list

let event = { ...i, display_name: i.summary ? i.summary : i.title, start_time: this.eventTime(i.start), end_time: this.eventTime(i.end), all_day: this.eventAllDay(i), format: "relative", item_type: "calendar_event" };
let event = { ...i, display_name: i.summary ? i.summary : i.title, start_time: this.eventTime(i.start), end_time: this.eventTime(i.end), all_day: this.eventAllDay(i), format: this._config.calendar_time_format ? this._config.calendar_time_format : "relative", item_type: "calendar_event" };
let startDateTime = this.moment(new Date(event.start_time));
let endDateTime = this.moment(new Date(event.end_time));
let eventTime = "";
Expand Down

0 comments on commit 5e81402

Please sign in to comment.