Skip to content

Allow to configure KNX time, date & datetime entities via UI#157603

Merged
farmio merged 5 commits into
home-assistant:devfrom
Abestanis:feature/knx_time_ui
Dec 2, 2025
Merged

Allow to configure KNX time, date & datetime entities via UI#157603
farmio merged 5 commits into
home-assistant:devfrom
Abestanis:feature/knx_time_ui

Conversation

@Abestanis
Copy link
Copy Markdown
Contributor

@Abestanis Abestanis commented Dec 1, 2025

Proposed change

Support KNX time, date and datetime entity configuration from UI.

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 1, 2025

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 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.

@Abestanis Abestanis force-pushed the feature/knx_time_ui branch from a636bb0 to c8785bd Compare December 1, 2025 01:22
@Abestanis Abestanis marked this pull request as ready for review December 1, 2025 01:29
@farmio farmio requested a review from Copilot December 1, 2025 05:19
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 UI configuration support for KNX time, date, and datetime entities, allowing users to configure these entities through the Home Assistant UI instead of requiring YAML configuration. This complements the existing YAML configuration method and brings these platforms in line with other KNX platforms that already support UI configuration.

  • Refactored entity classes to support both YAML and UI configuration patterns
  • Added schema definitions for time, date, and datetime platforms in the entity store
  • Created comprehensive tests for both entity creation and loading from storage

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
homeassistant/components/knx/time.py Refactored to support both YAML (KnxYamlTimeEntity) and UI (KnxUiTimeEntity) configuration with shared base class
homeassistant/components/knx/date.py Refactored to support both YAML (KnxYamlDateEntity) and UI (KnxUiDateEntity) configuration with shared base class
homeassistant/components/knx/datetime.py Refactored to support both YAML (KnxYamlDateTimeEntity) and UI (KnxUiDateTimeEntity) configuration with shared base class
homeassistant/components/knx/const.py Added time, date, and datetime platforms to SUPPORTED_PLATFORMS_UI
homeassistant/components/knx/storage/const.py Added constants for group address configuration (CONF_GA_TIME, CONF_GA_DATE, CONF_GA_DATETIME)
homeassistant/components/knx/storage/entity_store_schema.py Added schema definitions for time, date, and datetime entities with validation for DPT types
homeassistant/components/knx/strings.json Added UI strings for entity configuration dialogs
tests/components/knx/test_time.py Added tests for UI entity creation and loading from storage
tests/components/knx/test_date.py Added tests for UI entity creation and loading from storage
tests/components/knx/test_datetime.py Added tests for UI entity creation and loading from storage
tests/components/knx/snapshots/test_websocket.ambr Updated snapshots with schema validation for new platforms
tests/components/knx/fixtures/config_store_*.json Added test fixtures for loading entities from storage

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Comment thread homeassistant/components/knx/strings.json Outdated
Comment thread homeassistant/components/knx/strings.json Outdated
Comment thread homeassistant/components/knx/date.py Outdated
Copy link
Copy Markdown
Member

@farmio farmio left a comment

Choose a reason for hiding this comment

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

Thank you very much for your contribution 😃

Here are some - mostly stylistic / nit-picky - suggestions I have found

Comment thread homeassistant/components/knx/date.py Outdated
Comment thread homeassistant/components/knx/date.py Outdated
Comment thread homeassistant/components/knx/datetime.py Outdated
Comment thread homeassistant/components/knx/strings.json Outdated
Comment thread homeassistant/components/knx/strings.json Outdated
Comment thread homeassistant/components/knx/date.py Outdated


class KNXDateTimeEntity(KnxYamlEntity, DateTimeEntity, RestoreEntity):
class _KNXDateTimeEntity(DateTimeEntity, RestoreEntity):
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.

Nitpick: Other platforms don't add "Entity" for their platform classes. For consistency, consider to use _KnxDateTime as class name. (same for KnxYamlDateTime and KnxUiDateTime).

Comment thread tests/components/knx/test_date.py Outdated
Comment on lines +124 to +125
# date_without_state_address
await knx.assert_no_telegram()
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.

Suggested change
# date_without_state_address
await knx.assert_no_telegram()

Remaining unasserted telegrams are checked at test-teardown so we don't need to do this explicitly.

Comment thread tests/components/knx/test_date.py Outdated
# date_with_state_address
await knx.assert_read(
"0/0/2", response=(0x18, 0x02, 0x18), ignore_order=True
) # current
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.

Suggested change
) # current
)

DATE_KNX_SCHEMA = vol.Schema(
{
vol.Required(CONF_GA_DATE): GASelector(
passive=False, write_required=True, valid_dpt="11.001"
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.

Why wouldn't we allow passive GAs here? And for time and datetime?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was not sure what the passive addresses would be used for. Right now we are using get_write to get the group_address and get_state for the group_address_state, so the passive addresses are discarded, hence it did not make sense to ask for any.

I guess having address aliasses for group_address could make sense, but it feels less usefull for the group_address_state. What do you think?

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.

It doesn't make a difference. xknx treats all of those the same - it doesn't send anything but updates from telegrams.

For other entities I've used get_state_and_passive for the state address. If no state address is set, this would result in a list with first item None and append the passive addresses. xknx stores list-tails as passive addresses, regardless of group_address or group_address_state.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I see, all of the passive addresses end up in RemoteValue.passive_group_addresses anyways. Thanks for the explanation, I'll stick to get_state_and_passive then. 👍

@home-assistant home-assistant Bot marked this pull request as draft December 1, 2025 09:05
@home-assistant
Copy link
Copy Markdown
Contributor

home-assistant Bot commented Dec 1, 2025

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.

@Abestanis Abestanis force-pushed the feature/knx_time_ui branch from d631394 to 65e9235 Compare December 2, 2025 19:20
@Abestanis Abestanis force-pushed the feature/knx_time_ui branch from 65e9235 to 8049f75 Compare December 2, 2025 21:12
@Abestanis Abestanis marked this pull request as ready for review December 2, 2025 21:21
@home-assistant home-assistant Bot requested a review from farmio December 2, 2025 21:21
Copy link
Copy Markdown
Member

@farmio farmio left a comment

Choose a reason for hiding this comment

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

Great 👍 Thank you very much!

@farmio
Copy link
Copy Markdown
Member

farmio commented Dec 2, 2025

Do you, by any chance, have a clue why the tests failed when "passive": [] was omitted in the snapshots? I would have expected get_state_and_passive() to just ignore that 🤔

@Abestanis
Copy link
Copy Markdown
Contributor Author

Do you, by any chance, have a clue why the tests failed when "passive": [] was omitted in the snapshots?

The problem was not the passive, it was the fact that state was set to [] before in the test fixture, so get_state_and_passive returned [[]]. Before it worked because get_state just returned a [], which was valid.

This was my bad, I copied another fixture and at that point didn't realize that all passives end up in the same place, so I assumed that write and state would be a str | list, so I turned {"write": "0/0/1", "state": "0/0/2", "passive": []} into {"write": "0/0/1", "state": []} when I removed the passive key.

@farmio
Copy link
Copy Markdown
Member

farmio commented Dec 2, 2025

Ah great, thanks for explaining this. I was just worried that, whenever we do a passive=False to passive=True migration for something, things might break 😬

@farmio farmio changed the title Allow to configure knx time, date & datetime entities via the UI Allow to configure KNX time, date & datetime entities via UI Dec 2, 2025
@farmio farmio merged commit 9823621 into home-assistant:dev Dec 2, 2025
36 checks passed
@Abestanis Abestanis deleted the feature/knx_time_ui branch December 2, 2025 22:46
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants