Skip to content

Commit

Permalink
feat: Support for auto-entities
Browse files Browse the repository at this point in the history
  • Loading branch information
RomRider committed Feb 1, 2021
1 parent 3df6aed commit 060e4c0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ However, some things might be broken :grin:
- [Aggregating data](#aggregating-data)
- [Compare data from today with yesterday](#compare-data-from-today-with-yesterday)
- [Change the line thickness](#change-the-line-thickness)
- [Use apexcharts-card auto-entities](#use-apexcharts-card-auto-entities)

## Installation

Expand Down Expand Up @@ -503,4 +504,19 @@ series:
series:
- entity: sensor.temperature
- entity: sensor.humidity
```
```

### Use apexcharts-card auto-entities

This requires the [auto-entities card](https://github.com/thomasloven/lovelace-auto-entities)

```yaml
type: custom:auto-entities
filter:
include:
- entity_id: sensor.temperature*
options:
entity: this.entity_id
card:
type: custom:apexcharts-card
```
29 changes: 17 additions & 12 deletions src/apexcharts-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,27 +202,32 @@ class ChartsCard extends LitElement {
}

public setConfig(config: ChartCardExternalConfig) {
const configDup = JSON.parse(JSON.stringify(config));
if (configDup.entities) {
configDup.series = configDup.entities;
delete configDup.entities;
}
const { ChartCardExternalConfig } = createCheckers(exportedTypeSuite);
ChartCardExternalConfig.strictCheck(config);
if (config.update_interval) {
this._interval = validateInterval(config.update_interval, 'update_interval');
ChartCardExternalConfig.strictCheck(configDup);
if (configDup.update_interval) {
this._interval = validateInterval(configDup.update_interval, 'update_interval');
}
if (config.graph_span) {
this._graphSpan = validateInterval(config.graph_span, 'graph_span');
if (configDup.graph_span) {
this._graphSpan = validateInterval(configDup.graph_span, 'graph_span');
}
if (config.span?.offset) {
this._offset = validateOffset(config.span.offset, 'span.offset');
if (configDup.span?.offset) {
this._offset = validateOffset(configDup.span.offset, 'span.offset');
}
if (config.span?.end && config.span?.start) {
if (configDup.span?.end && configDup.span?.start) {
throw new Error(`span: Only one of 'start' or 'end' is allowed.`);
}
config.series.forEach((serie, index) => {
configDup.series.forEach((serie, index) => {
if (serie.offset) {
this._seriesOffset[index] = validateOffset(serie.offset, `series[${index}].offset`);
}
});
if (config.update_delay) {
this._updateDelay = validateInterval(config.update_delay, `update_delay`);
if (configDup.update_delay) {
this._updateDelay = validateInterval(configDup.update_delay, `update_delay`);
}

this._config = mergeDeep(
Expand All @@ -232,7 +237,7 @@ class ChartsCard extends LitElement {
useCompress: false,
show: { loading: true },
},
JSON.parse(JSON.stringify(config)),
configDup,
);

if (this._config) {
Expand Down

0 comments on commit 060e4c0

Please sign in to comment.