Skip to content

Commit 5e81402

Browse files
committed
Clear cache on refresh of page or config change and calendar_time_format config setting
1 parent 22eaa14 commit 5e81402

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ If this is set, it is used as the key for cacheing the feed in Local Storage, ot
5757
### calendars (optional)
5858
This is a list of calendar entities you want events to display for in your feed.
5959

60+
### calendar_time_format (optional, defaults to relative, added in 0.6.2)
61+
How the calendar event timestamp should be formatted.
62+
Valid values are: relative, date, time and datetime.
63+
6064
### calendar_days_back (optional, defaults to 0, added in 0.3.5b2)
6165
The number of days before the current day to include calendar events for in the feed
6266

lovelace-home-feed-card.js

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ class HomeFeedCard extends LitElement {
242242
return this._config.card_id ? this._config.card_id : this.pageId + this._config.title;
243243
}
244244

245+
get editMode() {
246+
let parentNodeName = this.parentElement && this.parentElement.nodeName;
247+
return parentNodeName == "HUI-CARD-PREVIEW";
248+
}
249+
245250
clearCache() {
246251
localStorage.removeItem('home-feed-card-events' + this.cacheId);
247252
localStorage.removeItem('home-feed-card-eventsLastUpdate' + this.cacheId);
@@ -258,6 +263,11 @@ class HomeFeedCard extends LitElement {
258263
this.calendars = this._config.calendars;
259264
this.oldStates = {};
260265

266+
if(!this.editMode)
267+
{
268+
console.log("Clearing Cache");
269+
this.clearCache();
270+
}
261271
setTimeout(() => this.buildIfReady(), 10);
262272
}
263273

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

534-
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" };
544+
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" };
535545
let startDateTime = this.moment(new Date(event.start_time));
536546
let endDateTime = this.moment(new Date(event.end_time));
537547
let eventTime = "";

0 commit comments

Comments
 (0)