Support KNX sensor entity configuration from UI#158498
Conversation
|
Hey there @Julius2342, @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 adds support for configuring KNX sensor entities through the Home Assistant UI, extending the existing UI configuration capabilities for KNX integrations. The implementation introduces DPT (Data Point Type) metadata serialization, UI entity classes, and schema definitions to enable frontend sensor configuration.
Key Changes
- Introduces a new DPT metadata system that maps KNX data point types to Home Assistant sensor attributes (device class, state class, units)
- Adds UI configuration schema for sensor entities with support for device class, state class, and force update options
- Refactors sensor entity classes to support both YAML and UI configuration methods
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| homeassistant/components/knx/dpt.py | New module providing cached DPT metadata with sensor device/state class mappings |
| homeassistant/components/knx/sensor.py | Refactored to support UI entities; extracts common base class and adds KnxUiSensor implementation |
| homeassistant/components/knx/storage/entity_store_schema.py | Adds SENSOR_KNX_SCHEMA defining UI configuration fields with device class, state class, and always_callback options |
| homeassistant/components/knx/storage/knx_selector.py | Extends GASelector to support DPT class lists for filtering numeric/string types |
| homeassistant/components/knx/websocket.py | Exposes DPT metadata to frontend via get_base_data WebSocket command |
| homeassistant/components/knx/storage/const.py | Adds CONF_ALWAYS_CALLBACK constant for sensor configuration |
| homeassistant/components/knx/const.py | Adds Platform.SENSOR to SUPPORTED_PLATFORMS_UI list |
| homeassistant/components/knx/strings.json | Adds sensor entity translations including field labels and descriptions |
| tests/components/knx/snapshots/test_websocket.ambr | Snapshot update for sensor schema structure validation |
| "7_002": "Time period", | ||
| "7_003": "Time period (10 ms)", | ||
| "7_004": "Time period (100 ms)", | ||
| "7_005": "[%key:component::knx::selector::dpt::options::7_002%]", | ||
| "7_006": "[%key:component::knx::selector::dpt::options::7_002%]", | ||
| "7_007": "[%key:component::knx::selector::dpt::options::7_002%]", |
There was a problem hiding this comment.
I would consider it a bad practice if we show 4 the same things in the UI but they all have different meanings
There was a problem hiding this comment.
This is
- Time period ms
- Time period sec
- Time period min
- Time period h
But we display the number left and the unit right next to the name anyway, so I figured it would be better have fewer translation items.
There was a problem hiding this comment.
How do you mean next to the name, it's a selector right?
There was a problem hiding this comment.
This is not used by a SelectSelector, but by a custom KNX Group Address Selector (GASelector class).
See the second image in the PR description.
There was a problem hiding this comment.
I've moved DPT translations into config_panel root key to avoid confusion with HA selector options.
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
|
Do we also have logic that aborts adding a sensor with invalid combinations? For example measurement angle + power or something |
|
Yes, there is validation logic for state_class, device_class and unit. See It's pretty much the same as used in template sensors. |
Co-authored-by: Norbert Rittel <norbert@rittel.de>
ff53280 to
2f15f5b
Compare
Proposed change
Support KNX sensor entity configuration from UI
knx-frontendlibrary with Add DPT dialog-selector for classes of DPTs XKNX/knx-frontend#290 I'll merge and release this when this is approved since there are some minor cross-dependencies (a websocket response is changed and translation paths have to match). Update knx-frontend to 2025.12.19.150946 #159446Type 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: