Fix adjusting 5-minute statistics (#69921)
This commit is contained in:
parent
a9742cc445
commit
80ff1ecb2a
2 changed files with 23 additions and 10 deletions
|
@ -1316,17 +1316,20 @@ def adjust_statistics(
|
|||
if statistic_id not in metadata:
|
||||
return True
|
||||
|
||||
tables: tuple[type[Statistics | StatisticsShortTerm], ...] = (
|
||||
Statistics,
|
||||
_adjust_sum_statistics(
|
||||
session,
|
||||
StatisticsShortTerm,
|
||||
metadata[statistic_id][0],
|
||||
start_time,
|
||||
sum_adjustment,
|
||||
)
|
||||
|
||||
_adjust_sum_statistics(
|
||||
session,
|
||||
Statistics,
|
||||
metadata[statistic_id][0],
|
||||
start_time.replace(minute=0),
|
||||
sum_adjustment,
|
||||
)
|
||||
for table in tables:
|
||||
_adjust_sum_statistics(
|
||||
session,
|
||||
table,
|
||||
metadata[statistic_id][0],
|
||||
start_time,
|
||||
sum_adjustment,
|
||||
)
|
||||
|
||||
return True
|
||||
|
|
|
@ -2464,6 +2464,16 @@ def test_compile_statistics_hourly_daily_monthly_summary(
|
|||
},
|
||||
]
|
||||
|
||||
# Adjust the inserted statistics
|
||||
sum_adjustment = -10
|
||||
sum_adjustement_start = zero + timedelta(minutes=65)
|
||||
for i in range(13, 24):
|
||||
expected_sums["sensor.test4"][i] += sum_adjustment
|
||||
recorder.async_adjust_statistics(
|
||||
"sensor.test4", sum_adjustement_start, sum_adjustment
|
||||
)
|
||||
wait_recording_done(hass)
|
||||
|
||||
stats = statistics_during_period(hass, zero, period="5minute")
|
||||
expected_stats = {
|
||||
"sensor.test1": [],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue