From f5aa2e36e1d792a5c73fb69a028ad5e71e9a0d68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Wiedemann?= Date: Mon, 1 Mar 2021 10:10:21 +0000 Subject: [PATCH] fix(start_with_last): `start_with_last` would sometimes throw --- .devcontainer/ui-lovelace.yaml | 21 +++++++++++++++++++++ src/graphEntry.ts | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.devcontainer/ui-lovelace.yaml b/.devcontainer/ui-lovelace.yaml index e062dd5..3eb21c2 100644 --- a/.devcontainer/ui-lovelace.yaml +++ b/.devcontainer/ui-lovelace.yaml @@ -882,3 +882,24 @@ views: func: first duration: 10min start_with_last: true + - type: custom:apexcharts-card + graph_span: 1 week + span: + end: week + all_series_config: + type: column + extend_to_end: false + group_by: + fill: 'null' + series: + - entity: sensor.random0_100 + name: last + group_by: + func: last + duration: 10min + - entity: sensor.random0_100 + name: first + group_by: + func: first + duration: 10min + start_with_last: true diff --git a/src/graphEntry.ts b/src/graphEntry.ts index 6fe9e1f..f0d6f59 100644 --- a/src/graphEntry.ts +++ b/src/graphEntry.ts @@ -394,7 +394,7 @@ export default class GraphEntry { } if (this._config.group_by.start_with_last) { if (index > 0) { - if (bucket.data[0][0] !== bucket.timestamp) { + if (bucket.data.length === 0 || bucket.data[0][0] !== bucket.timestamp) { const prevBucketData = buckets[index - 1].data; bucket.data.unshift([bucket.timestamp, prevBucketData[prevBucketData.length - 1][1]]); }