Store deleted duplicated statistics in .storage (#62574)

This commit is contained in:
Erik Montnemery 2021-12-22 14:27:56 +01:00 committed by GitHub
parent 75e8a2ec77
commit 2f8e65a9b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View file

@ -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:

View file

@ -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)