Skip to content

Support KNX sensor entity configuration from UI#158498

Merged
farmio merged 10 commits into
devfrom
knx-ui-sensor
Dec 19, 2025
Merged

Support KNX sensor entity configuration from UI#158498
farmio merged 10 commits into
devfrom
knx-ui-sensor

Conversation

@farmio
Copy link
Copy Markdown
Member

@farmio farmio commented Dec 9, 2025

Proposed change

Support KNX sensor entity configuration from UI

Bildschirmfoto 2025-12-12 um 10 54 53 Bildschirmfoto 2025-12-14 um 11 51 21

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

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 link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link
Copy Markdown
Contributor

home-assistant Bot commented Dec 9, 2025

Hey there @Julius2342, @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 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 add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@farmio farmio marked this pull request as ready for review December 9, 2025 22:22
@farmio farmio requested a review from marvin-w as a code owner December 9, 2025 22:22
Copilot AI review requested due to automatic review settings December 9, 2025 22:22
@farmio farmio marked this pull request as draft December 9, 2025 22:22
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 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

Comment thread homeassistant/components/knx/sensor.py
@farmio farmio marked this pull request as ready for review December 10, 2025 10:19
Comment thread homeassistant/components/knx/strings.json Outdated
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

Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.

Comment on lines +739 to +744
"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%]",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would consider it a bad practice if we show 4 the same things in the UI but they all have different meanings

Copy link
Copy Markdown
Member Author

@farmio farmio Dec 15, 2025

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How do you mean next to the name, it's a selector right?

Copy link
Copy Markdown
Member Author

@farmio farmio Dec 15, 2025

Choose a reason for hiding this comment

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

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.

https://github.com/XKNX/knx-frontend/pull/290/changes#diff-0cc578bbd1fef9dcde8c8b91f5a3c495168e727cf861ab8ace8de29425dcbafeR33

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've moved DPT translations into config_panel root key to avoid confusion with HA selector options.

@home-assistant home-assistant Bot marked this pull request as draft December 15, 2025 19:21
@home-assistant
Copy link
Copy Markdown
Contributor

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@joostlek
Copy link
Copy Markdown
Member

Do we also have logic that aborts adding a sensor with invalid combinations? For example measurement angle + power or something

@farmio
Copy link
Copy Markdown
Member Author

farmio commented Dec 15, 2025

Yes, there is validation logic for state_class, device_class and unit. See _validate_sensor_attributes validator function in entity_store_schema.py https://github.com/home-assistant/core/pull/158498/changes#diff-2eaf922cfc4f971f2e0c2c7f627b266e0079327c01b369d938e569194262001aR524

It's pretty much the same as used in template sensors.

@farmio farmio added the noteworthy Marks a PR as noteworthy and should be in the release notes (in case it normally would not appear) label Dec 18, 2025
@farmio farmio merged commit 37d3b73 into dev Dec 19, 2025
36 checks passed
@farmio farmio deleted the knx-ui-sensor branch December 19, 2025 18:20
Comment thread homeassistant/components/knx/strings.json
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

by-code-owner cla-signed has-tests integration: knx new-feature noteworthy Marks a PR as noteworthy and should be in the release notes (in case it normally would not appear) Quality Scale: silver

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants