Migrate to knx telegram store#169700
Draft
martinhoefling wants to merge 2 commits intohome-assistant:devfrom
Draft
Migrate to knx telegram store#169700martinhoefling wants to merge 2 commits intohome-assistant:devfrom
martinhoefling wants to merge 2 commits intohome-assistant:devfrom
Conversation
…tore. This step is a preparation for a refactoring, that allows using SQL databases as long term storage.
Contributor
There was a problem hiding this comment.
It seems you haven't yet signed a CLA. Please do so here.
Once you do that we will be able to review and accept this pull request.
Thanks!
Contributor
|
Hey there @Julius2342, @farmio, @marvin-w, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR migrates the KNX integration’s telegram history from the previous Home Assistant storage approach to the new knx-telegram-store backend, and exposes querying via websocket/config options.
Changes:
- Add
knx-telegram-storedependency and wire KNX telegram persistence to memory/sqlite/postgres backends. - Add a new websocket command (
knx/query_telegrams) and switch the group monitor history to query the store. - Update KNX options flow and tests to cover the new telegram store behavior.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
homeassistant/components/knx/telegrams.py |
Replace JSON store with knx-telegram-store and add backend init/eviction logic. |
homeassistant/components/knx/knx_module.py |
Adjust module startup/shutdown to initialize/close telegram storage. |
homeassistant/components/knx/websocket.py |
Query telegram history from the store and add knx/query_telegrams. |
homeassistant/components/knx/config_flow.py |
Add options flow steps for selecting/configuring telegram storage backend. |
homeassistant/components/knx/__init__.py |
Remove additional files on config entry removal (including sqlite DB). |
homeassistant/components/knx/const.py |
Add new config keys/defaults for telegram store backend. |
homeassistant/components/knx/strings.json |
Add repair issue + options flow strings for telegram storage configuration. |
homeassistant/components/knx/manifest.json |
Add knx-telegram-store==0.1.0 to requirements. |
requirements_all.txt / requirements_test_all.txt |
Add knx-telegram-store==0.1.0. |
tests/components/knx/test_websocket.py |
Add websocket test for knx/query_telegrams. |
tests/components/knx/test_telegrams.py |
Rewrite telegram history tests for store backends (memory/sqlite) + disabled history. |
tests/components/knx/test_config_flow.py |
Update config flow tests for new backend options/steps. |
tests/components/knx/conftest.py |
Ensure persistent_notification is available in KNX test setup. |
tests/components/knx/test_init.py |
Adjust expected file unlink count during entry removal. |
Comment on lines
+1097
to
+1102
| db_path = self.initial_data.get( | ||
| CONF_KNX_TELEGRAM_DB_PATH, TELEGRAM_DB_PATH_DEFAULT | ||
| ) | ||
| full_path = Path(self.hass.config.path(STORAGE_DIR, db_path)) | ||
| db_exists_info = "File exists" if full_path.exists() else "File does not exist" | ||
|
|
Comment on lines
+1194
to
+1203
| dsn_preview = self._build_dsn(parsed) if current_dsn else "No DSN configured" | ||
|
|
||
| return self.async_show_form( | ||
| step_id="telegram_store_postgres", | ||
| data_schema=vol.Schema(data_schema), | ||
| last_step=True, | ||
| description_placeholders={ | ||
| "dsn_preview": dsn_preview, | ||
| }, | ||
| ) |
Comment on lines
+1137
to
+1146
| if user_input is not None: | ||
| dsn = self._build_dsn(user_input) | ||
| return self.finish_flow( | ||
| KNXConfigEntryData( | ||
| telegram_retention_days=user_input[ | ||
| CONF_KNX_TELEGRAM_RETENTION_DAYS | ||
| ], | ||
| telegram_dsn=dsn, | ||
| ) | ||
| ) |
Comment on lines
+199
to
+202
| (storage_dir / "knx/telegrams.db").unlink() | ||
| if db_path is not None: | ||
| with contextlib.suppress(FileNotFoundError): | ||
| (storage_dir / db_path).unlink() |
Comment on lines
+206
to
+210
| async def stop(self) -> None: | ||
| """Stop history store.""" | ||
| if self._async_remove_listener: | ||
| self._async_remove_listener() | ||
| await self.store.close() |
| await self.project.load_project(self.xknx) | ||
| await self.config_store.load_data() | ||
| await self.telegrams.load_history() | ||
| self.hass.async_create_task(self.telegrams.load_history()) |
Comment on lines
+173
to
+176
| self.hass.async_create_task( | ||
| self.hass.services.async_call( | ||
| "persistent_notification", | ||
| "create", |
Comment on lines
+178
to
+185
| "title": "KNX Telegram Storage Error", | ||
| "message": ( | ||
| f"The configured KNX telegram storage backend '{backend}' failed to initialize. " | ||
| "Home Assistant has fallen back to memory-only storage. " | ||
| "Telegram history will be lost on restart until the issue is resolved.\n\n" | ||
| f"**Configuration**: `{info}`\n" | ||
| f"**Error**: {err}" | ||
| ), |
Comment on lines
+938
to
+951
| self.hass.async_create_task( | ||
| self.hass.services.async_call( | ||
| "persistent_notification", | ||
| "create", | ||
| { | ||
| "title": "KNX Telegram Storage", | ||
| "message": ( | ||
| "The telegram storage backend has been changed. " | ||
| "Home Assistant will reload the KNX integration to apply the changes." | ||
| ), | ||
| "notification_id": "knx_telegram_backend_changed", | ||
| }, | ||
| ) | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Breaking change
Proposed change
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: