Skip to content

Commit a287f05

Browse files
authored
fix: Solve localizing a localized datetime (#104)
* fix: Solve localizing a localized datetime * fix: code review
1 parent b1c241e commit a287f05

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

custom_components/iec/coordinator.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,15 +405,18 @@ async def _insert_statistics(self, contract_id: int, is_smart_meter: bool) -> No
405405
key=lambda reading: reading.date
406406
.replace(minute=0, second=0, microsecond=0))
407407
readings_by_hour: dict[datetime, float] = {}
408+
if last_stat_req_hour and last_stat_req_hour.tzinfo is None:
409+
last_stat_req_hour = TIMEZONE.localize(last_stat_req_hour)
410+
408411
for key, group in grouped_new_readings_by_hour:
409412
group_list = list(group)
410413
if len(group_list) < 4:
411414
_LOGGER.debug(f"LongTerm Statistics - Skipping {key} since it's partial for the hour")
412415
continue
413-
if key <= TIMEZONE.localize(last_stat_req_hour):
414-
_LOGGER.debug(f"LongTerm Statistics -Skipping {key} data since it's already reported")
416+
if key <= last_stat_req_hour:
417+
_LOGGER.debug(f"LongTerm Statistics - Skipping {key} data since it's already reported")
415418
continue
416-
readings_by_hour[key] = sum(reading.value for reading in group_list)
419+
readings_by_hour[key] = sum(reading.value for reading in group)
417420

418421
consumption_metadata = StatisticMetaData(
419422
has_mean=False,

0 commit comments

Comments
 (0)