Skip to content

Comments

Use Home Assistant Store for ML data persistence#183

Merged
JohanAlvedal merged 1 commit intocodex/01from
codex/update-ml-storage-to-use-home-assistant-store
Jan 19, 2026
Merged

Use Home Assistant Store for ML data persistence#183
JohanAlvedal merged 1 commit intocodex/01from
codex/update-ml-storage-to-use-home-assistant-store

Conversation

@JohanAlvedal
Copy link
Owner

Motivation

  • Replace the hardcoded file-based ML persistence with Home Assistant's Store API to avoid relying on /config paths and to integrate with HA storage abstractions.
  • Preserve existing ML schema and version fields while keeping business logic, model calculations, and session collection behavior unchanged.
  • Provide a one-time import path from the legacy file so existing user data is preserved without deleting the old file.

Description

  • Introduced ML_STORAGE_KEY, ML_STORAGE_VERSION, and ML_LEGACY_DATA_FILENAME in ml_settings.py and replaced the old file path constant with storage metadata.
  • Reworked PumpSteerMLCollector in ml_adaptive.py to use homeassistant.helpers.storage.Store for async load/save and to store the Store instance on initialization.
  • Implemented a legacy-import flow that tries to read the old legacy file once via hass.config.path(...) (executed in the executor), imports it into the Store, and then continues using the Store without deleting the legacy file.
  • Kept version-mismatch handling robust and non-blocking by performing migrations and writing migrated defaults back to Store asynchronously, and ensured the collector uses _apply_loaded_data to populate in-memory fields.
  • Did not change any ML algorithm, session collection, summaries, or persisted data schema fields.

Testing

  • Ran pytest, which aborted during collection with ModuleNotFoundError: No module named 'homeassistant', so unit tests could not be executed in this environment.
  • Verified locally (code inspection and lint) that no hardcoded /config/... path remains and that Store async methods are used for load/save, and that the legacy import is attempted only if Store is empty.

Migration note: on startup the collector first attempts to load data from the HA Store; if no Store data exists it attempts to import the legacy pumpsteer_ml_data.json via hass.config.path(...) once, logs the import, saves the imported payload into Store, and continues using Store going forward while leaving the legacy file in place.


Codex Task

@JohanAlvedal JohanAlvedal merged commit cf1cc02 into codex/01 Jan 19, 2026
1 of 4 checks passed
@JohanAlvedal JohanAlvedal deleted the codex/update-ml-storage-to-use-home-assistant-store branch January 20, 2026 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant