From 6f5e82009025e61a54339acf5601ad432d090cd8 Mon Sep 17 00:00:00 2001 From: dfaour Date: Thu, 16 May 2024 11:44:03 +0000 Subject: [PATCH] Improve recorder statistics error messages (#113498) * Update statistics.py Added more detail error descriptions to make debugging easier * Update statistics.py formatting corrected --- homeassistant/components/recorder/statistics.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/recorder/statistics.py b/homeassistant/components/recorder/statistics.py index 572731a9fed..42aa6ec9df6 100644 --- a/homeassistant/components/recorder/statistics.py +++ b/homeassistant/components/recorder/statistics.py @@ -2044,7 +2044,7 @@ def _fast_build_sum_list( ] -def _sorted_statistics_to_dict( +def _sorted_statistics_to_dict( # noqa: C901 hass: HomeAssistant, session: Session, stats: Sequence[Row[Any]], @@ -2198,9 +2198,14 @@ def _async_import_statistics( for statistic in statistics: start = statistic["start"] if start.tzinfo is None or start.tzinfo.utcoffset(start) is None: - raise HomeAssistantError("Naive timestamp") + raise HomeAssistantError( + "Naive timestamp: no or invalid timezone info provided" + ) if start.minute != 0 or start.second != 0 or start.microsecond != 0: - raise HomeAssistantError("Invalid timestamp") + raise HomeAssistantError( + "Invalid timestamp: timestamps must be from the top of the hour (minutes and seconds = 0)" + ) + statistic["start"] = dt_util.as_utc(start) if "last_reset" in statistic and statistic["last_reset"] is not None: