diff --git a/src/apexcharts-card.ts b/src/apexcharts-card.ts index ecbd14f..c4b2e5c 100644 --- a/src/apexcharts-card.ts +++ b/src/apexcharts-card.ts @@ -50,14 +50,13 @@ localForage.config({ localForage .iterate((data, key) => { const value: EntityEntryCache = key.endsWith('-raw') ? data : decompress(data); + if (value.card_version !== pjson.version) { + localForage.removeItem(key); + } const start = new Date(); - if (value.span === undefined) { + start.setTime(start.getTime() - value.span); + if (new Date(value.last_fetched) < start) { localForage.removeItem(key); - } else { - start.setTime(start.getTime() - value.span); - if (new Date(value.last_fetched) < start) { - localForage.removeItem(key); - } } }) .catch((err) => { diff --git a/src/graphEntry.ts b/src/graphEntry.ts index fdc8151..87f29e9 100644 --- a/src/graphEntry.ts +++ b/src/graphEntry.ts @@ -8,6 +8,7 @@ import { HOUR_24, moment } from './const'; import parse from 'parse-duration'; import SparkMD5 from 'spark-md5'; import { ChartCardSpanExtConfig } from './types-config'; +import * as pjson from '../package.json'; export default class GraphEntry { private _history?: EntityEntryCache; @@ -171,12 +172,14 @@ export default class GraphEntry { if (history?.data.length) { history.span = this._graphSpan; history.last_fetched = new Date(); + history.card_version = pjson.version; if (history.data.length !== 0) { history.data.push(...newStateHistory); } } else { history = { span: this._graphSpan, + card_version: pjson.version, last_fetched: new Date(), data: newStateHistory, }; diff --git a/src/types.ts b/src/types.ts index bbb1f59..57b15da 100644 --- a/src/types.ts +++ b/src/types.ts @@ -20,6 +20,7 @@ export interface ChartCardSeriesConfig extends ChartCardSeriesExternalConfig { export interface EntityEntryCache { span: number; + card_version: string; last_fetched: Date; data: EntityCachePoints; }