Skip to content

Remove templates from schemas for service fields validation#150063

Merged
arturpragacz merged 7 commits into
home-assistant:devfrom
arturpragacz:h/config-validation/improve-service-fields
Oct 30, 2025
Merged

Remove templates from schemas for service fields validation#150063
arturpragacz merged 7 commits into
home-assistant:devfrom
arturpragacz:h/config-validation/improve-service-fields

Conversation

@arturpragacz
Copy link
Copy Markdown
Member

@arturpragacz arturpragacz commented Aug 5, 2025

Proposed change

Remove templates from schemas for entity service fields validation.

As the rendering of templates happens before the evaluation of the schema (in here), the schema was adjusted to not contain templates.

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

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

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 Aug 5, 2025

Hey there @RaHehl, mind taking a look at this pull request as it has been labeled with an integration (unifiprotect) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of unifiprotect 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 unifiprotect 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.

@home-assistant
Copy link
Copy Markdown
Contributor

home-assistant Bot commented Aug 5, 2025

Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration (websocket_api) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of websocket_api 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 websocket_api 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.

@home-assistant
Copy link
Copy Markdown
Contributor

home-assistant Bot commented Aug 5, 2025

Hey there @bdraco, mind taking a look at this pull request as it has been labeled with an integration (homekit) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of homekit 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 homekit 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.

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 improves validation of service fields by streamlining schema definitions and removing unnecessary template validation complexity. The main goal is to simplify service field validation while maintaining functionality for both regular and templated use cases.

Key changes:

  • Introduction of streamlined TARGET_FIELDS schema for LLM serialization
  • Refactoring of template validation to handle individual key-level templates
  • Simplification of service schemas in homekit and unifiprotect integrations

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
homeassistant/helpers/config_validation.py Adds new TARGET_FIELDS schema and refactors existing service field schemas to separate templated and non-templated versions
homeassistant/helpers/llm.py Updates selector serializer to use new TARGET_FIELDS instead of TARGET_SERVICE_FIELDS
tests/helpers/test_llm.py Updates test expectations to match simplified target schema structure
homeassistant/components/websocket_api/commands.py Removes template validation check that is no longer needed
homeassistant/components/unifiprotect/services.py Simplifies service schemas by removing unnecessary validation wrapping
homeassistant/components/homekit/__init__.py Simplifies unpair service schema to require only device_id
homeassistant/components/homekit/services.yaml Updates service definition to use fields instead of target
homeassistant/components/homekit/strings.json Adds field description for device_id in unpair service

Comment thread homeassistant/helpers/config_validation.py Outdated
Comment thread homeassistant/helpers/config_validation.py Outdated
@arturpragacz
Copy link
Copy Markdown
Member Author

Changes to homekit and unifiprotect could be extracted to separate PRs.

@MartinHjelmare
Copy link
Copy Markdown
Member

MartinHjelmare commented Aug 7, 2025

I don't understand why the four bullets are done in the same PR. I'd make 4-5 different PRs if they have no dependencies on each other.

@MartinHjelmare MartinHjelmare marked this pull request as draft August 7, 2025 10:35
@arturpragacz
Copy link
Copy Markdown
Member Author

@MartinHjelmare As I started working on it, I've noticed a bunch of other improvements along the way, so this commit grew in scope. You're right that it should be split up.

@arturpragacz arturpragacz force-pushed the h/config-validation/improve-service-fields branch from e334200 to 8458656 Compare August 7, 2025 23:00
@arturpragacz
Copy link
Copy Markdown
Member Author

@arturpragacz arturpragacz marked this pull request as ready for review August 7, 2025 23:07
@arturpragacz arturpragacz marked this pull request as draft August 7, 2025 23:25
@arturpragacz arturpragacz force-pushed the h/config-validation/improve-service-fields branch from b564525 to e3e54c0 Compare August 26, 2025 18:54
@arturpragacz arturpragacz marked this pull request as ready for review August 26, 2025 20:54
@arturpragacz arturpragacz removed the request for review from bdraco September 19, 2025 11:43
@arturpragacz arturpragacz changed the title Improve validation of service fields Improve validation of service fields in respect to templates Oct 6, 2025
Comment thread homeassistant/helpers/config_validation.py
@arturpragacz arturpragacz changed the title Improve validation of service fields in respect to templates Remove templates from schemas for service fields validation Oct 30, 2025
Comment thread homeassistant/helpers/config_validation.py
Comment thread homeassistant/helpers/config_validation.py Outdated
Comment thread homeassistant/helpers/config_validation.py Outdated
Comment thread homeassistant/helpers/config_validation.py Outdated
@home-assistant home-assistant Bot marked this pull request as draft October 30, 2025 15:24
@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.

@arturpragacz arturpragacz marked this pull request as ready for review October 30, 2025 16:01
Copy link
Copy Markdown
Contributor

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @arturpragacz 👍

@arturpragacz arturpragacz merged commit b157afa into home-assistant:dev Oct 30, 2025
59 of 62 checks passed
@arturpragacz arturpragacz deleted the h/config-validation/improve-service-fields branch October 30, 2025 17:46
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 31, 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.

5 participants