Add PostgreSQL backend and storage backend selection for KNX telegrams - #175673
Conversation
|
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
|
There was a problem hiding this comment.
Pull request overview
This PR extends the KNX integration's telegram storage subsystem (introduced for 2026.07) by adding an external PostgreSQL backend alongside the existing SQLite store, and a backend selector in the options flow. When PostgreSQL is chosen, a second options step collects host/port/user/password/database/TLS, assembles a DSN, validates the connection (10s timeout) with translated error mapping, and stores the DSN in config entry options. The DSN is redacted in diagnostics, the group monitor websocket base data now reports the concrete backend, and the knx-telegram-store dependency is bumped to 0.4.0 with the postgres extra. A config entry migration to v2.2 defaults existing entries to the SQLite backend and moves any DSN from entry data to options.
Changes:
- Add a
telegram_db_backendselector and atelegram_store_postgresoptions step with DSN build/parse/validation helpers and password reuse. - Select
BufferedPostgresStore/BufferedSqliteStoreinTelegrams, surface the backend viaisinstancein the websocket, and redact the DSN in diagnostics. - Bump
knx-telegram-store[sqlite,postgres]==0.4.0, add constants/typed options, migrate entries tov2.2, and add tests for the new flow and init paths.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
homeassistant/components/knx/config_flow.py |
Adds backend selector, PostgreSQL step, and DSN build/parse/validate helpers |
homeassistant/components/knx/telegrams.py |
Selects SQLite or PostgreSQL store based on configured backend |
homeassistant/components/knx/websocket.py |
Reports concrete backend via isinstance checks on the store |
homeassistant/components/knx/__init__.py |
Adds v2.2 migration setting default backend and moving DSN to options |
homeassistant/components/knx/const.py |
New backend/DSN constants and typed option fields |
homeassistant/components/knx/diagnostics.py |
Redacts the PostgreSQL DSN in diagnostics |
homeassistant/components/knx/strings.json |
Adds selector, form, and error translations |
homeassistant/components/knx/manifest.json |
Bumps dependency to knx-telegram-store[sqlite,postgres]==0.4.0 |
requirements_all.txt |
Mirrors the dependency bump |
tests/components/knx/test_config_flow.py |
Tests the PostgreSQL options flow, DSN parsing, failure/timeout paths |
tests/components/knx/test_telegrams.py |
Tests invalid backend and PostgreSQL init-failure paths |
tests/components/knx/test_init.py |
Tests the v2.x→v2.2 migration |
tests/components/knx/conftest.py |
Adds default backend to the mock config entry options |
tests/components/knx/snapshots/test_diagnostic.ambr |
Updates snapshots for the new option |
41dbcea to
c43d711
Compare
c43d711 to
c7af8db
Compare
c7af8db to
d0b2432
Compare
f868d92 to
2401782
Compare
Build on the SQLite telegram store by adding an external PostgreSQL
storage backend and a storage-backend selector to the options flow.
- Add a storage backend dropdown ("Internal storage" / "PostgreSQL") to the
communication settings step. SQLite routes to the existing store step;
PostgreSQL routes to a new step collecting host, port, user, password,
database and TLS, assembled into a DSN.
- Validate the PostgreSQL connection (with a 10s timeout) before saving,
mapping connection error kinds to translated form errors.
- Reuse the stored password when the PostgreSQL password field is left
blank and mask credentials when building/parsing the DSN.
- Construct a BufferedPostgresStore when the PostgreSQL backend is selected
and surface the backend in the group monitor websocket base data.
- Redact the telegram DSN in diagnostics.
- Pull in the postgres extra of knx-telegram-store (bumped to 0.4.0).
- Add tests for the PostgreSQL options flow, DSN parsing, invalid backend
handling, connection failure, timeout and the init failure path.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
- Drop DSN data->options migration that never shipped; comment when the 2.2 migration was introduced - Parse current DSN once in the postgres options step - Import knx-telegram-store at module level in config flow - Use else for the sqlite backend branch; remove unreachable invalid-backend handling and its test - Clarify that the TLS option does not verify the server certificate Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AC3osqhYegB84hvFNJLofB
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
- Make the store init and DSN check timeouts patchable constants and exercise real timeout expiry in tests instead of injecting TimeoutError - Annotate knx_setup fixture parameters as AsyncMock - Cover the malformed-DSN ValueError path in the options flow - knx-telegram-store 0.9.0 percent-decodes the database name in DSNs and makes TimescaleDB optional; drop the now unreachable missing_timescaledb form error Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KGK6rMuaq1Zs44Ry6Wk7XS
2eecb4e to
0d76b04
Compare
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KGK6rMuaq1Zs44Ry6Wk7XS
0.9.1 translates libpq's sslmode DSN parameter to asyncpg's ssl connect argument, fixing connections with TLS enabled. Size the write buffer to cover a full flush interval at the maximum KNX TP line rate so telegrams are not dropped between flushes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KGK6rMuaq1Zs44Ry6Wk7XS
Breaking change
No, builds on the introduced library for KNX Telegram storage in 2026.07
Proposed change
Build on the SQLite telegram store by adding an external PostgreSQL storage backend and a storage-backend selector to the options flow. Primary use case is to store long term history of KNX Telegrams in a separate time series database from HA for querying and multi tenancy with other analysis tools like Spectrum KNX.
Details
0.3.2->0.9.1). 0.9.0 percent-decodes the database name in DSNs and makes TimescaleDB optional with automatic detection; 0.9.1 translates libpq'ssslmodeDSN parameter to asyncpg'ssslconnect argument so TLS connections work. Release notes: https://github.com/XKNX/knx-telegram-store/releasesType 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: