Skip to content

Migrate to knx telegram store#169700

Draft
martinhoefling wants to merge 2 commits intohome-assistant:devfrom
martinhoefling:migrate-to-knx-telegram-store
Draft

Migrate to knx telegram store#169700
martinhoefling wants to merge 2 commits intohome-assistant:devfrom
martinhoefling:migrate-to-knx-telegram-store

Conversation

@martinhoefling
Copy link
Copy Markdown

Breaking change

Proposed change

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

…tore.

This step is a preparation for a refactoring, that allows using SQL databases as long term storage.
Copilot AI review requested due to automatic review settings May 3, 2026 18:54
Copy link
Copy Markdown
Contributor

@home-assistant home-assistant Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @martinhoefling

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!

@home-assistant
Copy link
Copy Markdown
Contributor

home-assistant Bot commented May 3, 2026

Hey there @Julius2342, @farmio, @marvin-w, mind taking a look at this pull request as it has been labeled with an integration (knx) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of knx can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign knx Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-store dependency 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",
},
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants