Skip to content

Commit

Permalink
fix: Ignore recorder when not required
Browse files Browse the repository at this point in the history
Fix #169
  • Loading branch information
RomRider committed Jul 4, 2021
1 parent f82f7e0 commit c28a7a6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .devcontainer/ui-lovelace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ views:
unit: Mbits/s
min: 0
max: 1000
group_by:
func: max
duration: 30min
- type: custom:apexcharts-card
chart_type: pie
header:
Expand Down
7 changes: 7 additions & 0 deletions src/apexcharts-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,13 @@ class ChartsCard extends LitElement {
}
this._graphs = this._config.series.map((serie, index) => {
serie.index = index;
serie.ignore_history = !!(
this._config?.chart_type &&
['donut', 'pie', 'radialBar'].includes(this._config?.chart_type) &&
(!serie.group_by || serie.group_by?.func === 'raw') &&
!serie.data_generator &&
!serie.offset
);
if (!this._headerColors[index]) {
this._headerColors[index] = defColors[index % defColors.length];
}
Expand Down
11 changes: 11 additions & 0 deletions src/graphEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@ export default class GraphEntry {
}
if (!this._entityState || this._updating) return false;
this._updating = true;

if (this._config.ignore_history) {
let currentState: null | number | string = this._entityState.state;
if (this._config.transform) {
currentState = this._applyTransform(currentState, this._entityState);
}
this._computedHistory = [[new Date(this._entityState.last_updated).getTime(), Number(currentState)]];
this._updating = false;
return true;
}

let history: EntityEntryCache | undefined = undefined;

if (this._config.data_generator) {
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface ChartCardSeriesConfig extends ChartCardSeriesExternalConfig {
start_with_last?: boolean;
};
show: ChartCardSeriesShowConfig;
ignore_history: boolean;
}

export interface ChartCardSeriesShowConfig extends ChartCardSeriesShowConfigExt {
Expand Down

0 comments on commit c28a7a6

Please sign in to comment.