From 2f8e65a9b02b082f491a9de559b92bc6d340f085 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Wed, 22 Dec 2021 14:27:56 +0100 Subject: [PATCH] Store deleted duplicated statistics in .storage (#62574) --- homeassistant/components/recorder/statistics.py | 5 +++-- tests/components/recorder/test_statistics.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/recorder/statistics.py b/homeassistant/components/recorder/statistics.py index 54ef5f2be67..319431171f0 100644 --- a/homeassistant/components/recorder/statistics.py +++ b/homeassistant/components/recorder/statistics.py @@ -30,6 +30,7 @@ from homeassistant.core import Event, HomeAssistant, callback from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import entity_registry from homeassistant.helpers.json import JSONEncoder +from homeassistant.helpers.storage import STORAGE_DIR import homeassistant.util.dt as dt_util import homeassistant.util.pressure as pressure_util import homeassistant.util.temperature as temperature_util @@ -368,8 +369,8 @@ def delete_duplicates(instance: Recorder, session: scoped_session) -> None: if non_identical_duplicates: isotime = dt_util.utcnow().isoformat() - backup_file_name = f".deleted_statistics/deleted_statistics.{isotime}.json" - backup_path = instance.hass.config.path(backup_file_name) + backup_file_name = f"deleted_statistics.{isotime}.json" + backup_path = instance.hass.config.path(STORAGE_DIR, backup_file_name) os.makedirs(os.path.dirname(backup_path), exist_ok=True) with open(backup_path, "w", encoding="utf8") as backup_file: diff --git a/tests/components/recorder/test_statistics.py b/tests/components/recorder/test_statistics.py index 42581cf8adf..296409d984f 100644 --- a/tests/components/recorder/test_statistics.py +++ b/tests/components/recorder/test_statistics.py @@ -993,7 +993,7 @@ def test_delete_duplicates_non_identical(caplog, tmpdir): assert "Found duplicated" not in caplog.text isotime = dt_util.utcnow().isoformat() - backup_file_name = f".deleted_statistics/deleted_statistics.{isotime}.json" + backup_file_name = f".storage/deleted_statistics.{isotime}.json" with open(hass.config.path(backup_file_name)) as backup_file: backup = json.load(backup_file)