diff --git a/homeassistant/components/recorder/statistics.py b/homeassistant/components/recorder/statistics.py index 59316591be2..9db1e532f4c 100644 --- a/homeassistant/components/recorder/statistics.py +++ b/homeassistant/components/recorder/statistics.py @@ -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 diff --git a/tests/components/sensor/test_recorder.py b/tests/components/sensor/test_recorder.py index 33550495589..825aec7904c 100644 --- a/tests/components/sensor/test_recorder.py +++ b/tests/components/sensor/test_recorder.py @@ -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": [],