From 54e330e49aaf97a81716356194db890530ac6b56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20Sp=C3=B6rk?= Date: Sat, 11 Nov 2023 13:06:59 +0100 Subject: [PATCH] Fix #196 --- custom_components/wnsm/statistics_sensor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/wnsm/statistics_sensor.py b/custom_components/wnsm/statistics_sensor.py index 7acdf63..c1b62d9 100644 --- a/custom_components/wnsm/statistics_sensor.py +++ b/custom_components/wnsm/statistics_sensor.py @@ -176,8 +176,8 @@ async def _import_historical_data(self, smartmeter: Smartmeter): for ts, usage in sorted(dates.items(), key=itemgetter(0)): total_usage += usage statistics.append(StatisticData(start=ts, sum=total_usage, state=usage)) - - _LOGGER.debug(f"Importing statistics from {statistics[0]} to {statistics[-1]}") + if len(statistics) > 0: + _LOGGER.debug(f"Importing statistics from {statistics[0]} to {statistics[-1]}") async_import_statistics(self.hass, metadata, statistics) async def _import_statistics(self, smartmeter: Smartmeter, start: datetime, total_usage: Decimal):