Skip to content

Add app selector type to fix HA 2026.x service field validation errors#227

Closed
Copilot wants to merge 2 commits intodevfrom
copilot/fix-validation-errors-service-fields
Closed

Add app selector type to fix HA 2026.x service field validation errors#227
Copilot wants to merge 2 commits intodevfrom
copilot/fix-validation-errors-service-fields

Conversation

Copy link
Contributor

Copilot AI commented Mar 1, 2026

HA 2026.x introduced a new app selector type. Since ServiceFieldSelector didn't define it and BaseModel uses extra="forbid", any service with an app-typed field (e.g. hassio.addon_start) caused a ValidationError and broke get_domain() / get_domains() entirely.

Changes

  • ServiceFieldSelectorApp — new model with optional name and slug fields, matching the HA frontend AppSelector TypeScript interface
  • ServiceFieldSelector.app — new optional field wired to ServiceFieldSelectorApp
# Previously raised pydantic_core.ValidationError: Extra inputs are not permitted
field = ServiceField(required=True, example="core_ssh", selector={"app": {}})
Original prompt

This section details on the original issue you should resolve

<issue_title>[Library Bug] validation errors for Service fields.app.ServiceField.selector.app version 2026.01.1 and later</issue_title>
<issue_description>Describe the bug
Installation method Home Assistant OS
Core 2026.2.0
Supervisor 2026.01.1
Operating System 17.0
Frontend 20260128.6

upgraded to 2026.2.0 and now api is broken

To Reproduce
Steps to reproduce the behavior:
Upgrade to 2026.2.0
Try to get domains see error below

Traceback (most recent call last):
  File "/home/konetzed/venv/ha/shed_lights.py", line 18, in <module>
    switch = client.get_domain("switch")
  File "/home/konetzed/venv/ha/lib/python3.13/site-packages/homeassistant_api/rawclient.py", line 288, in get_domain
    return self.get_domains().get(domain_id)
           ~~~~~~~~~~~~~~~~^^
  File "/home/konetzed/venv/ha/lib/python3.13/site-packages/homeassistant_api/rawclient.py", line 281, in get_domains
    return {domain.domain_id: domain for domain in domains}
                                                   ^^^^^^^
  File "/home/konetzed/venv/ha/lib/python3.13/site-packages/homeassistant_api/rawclient.py", line 278, in <lambda>
    lambda json: Domain.from_json(json, client=cast(Client, self)),
                 ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/konetzed/venv/ha/lib/python3.13/site-packages/homeassistant_api/models/domains.py", line 68, in from_json
    domain._add_service(service_id, **data)
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/home/konetzed/venv/ha/lib/python3.13/site-packages/homeassistant_api/models/domains.py", line 76, in _add_service
    service_id: Service(
                ~~~~~~~^
        service_id=service_id,
        ^^^^^^^^^^^^^^^^^^^^^^
        domain=self,
        ^^^^^^^^^^^^
        **data,
        ^^^^^^^
    )
    ^
  File "/home/konetzed/venv/ha/lib/python3.13/site-packages/pydantic/main.py", line 250, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 5 validation errors for Service
fields.app.ServiceField.selector.app
  Extra inputs are not permitted [type=extra_forbidden, input_value={}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/extra_forbidden
fields.app.ServiceFieldCollection.fields
  Field required [type=missing, input_value={'required': True, 'examp...'selector': {'app': {}}}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
fields.app.ServiceFieldCollection.required
  Extra inputs are not permitted [type=extra_forbidden, input_value=True, input_type=bool]
    For further information visit https://errors.pydantic.dev/2.12/v/extra_forbidden
fields.app.ServiceFieldCollection.example
  Extra inputs are not permitted [type=extra_forbidden, input_value='core_ssh', input_type=str]
    For further information visit https://errors.pydantic.dev/2.12/v/extra_forbidden
fields.app.ServiceFieldCollection.selector
  Extra inputs are not permitted [type=extra_forbidden, input_value={'app': {}}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/extra_forbidden
(ha) konetzed@serenity ~/venv/ha $ 

The Code

(ha) konetzed@serenity ~/venv/ha $ cat shed_lights.py 
#!/home/konetzed/venv/ha/bin/python
import os

from homeassistant_api import Client

api_url = <REMOVED FOR SAFETY>  # Something like http://localhost:8123/api
token = <REMOVED FOR SAFETY>

# Used to aunthenticate yourself with homeassistant
# See the documentation on how to obtain a Long Lived Access Token

assert token is not None

with Client(
    api_url,
    token,
) as client:  # Create Client object and check that its running.
    switch = client.get_domain("switch")

    # Tells Home Assistant to trigger the toggle service on the given entity_id
    switch.toggle(entity_id="switch.shed_main_lights")

Expected behavior
It should work :)

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Debian
  • OS Version 13
  • HomeAssistantAPI Version: 5.0.2.post2
Package              Version
-------------------- -----------
aiohappyeyeballs     2.6.1
aiohttp              3.13.0
aiohttp-client-cache 0.14.1
aiosignal            1.4.0
annotated-types      0.7.0
attrs                25.4.0
cattrs               25.3.0
certifi              2025.10.5
charset-normalizer   3.4.3
frozenlist           1.8.0
HomeAssistant-API    5.0.2.post2
idna                 3.10
itsdangerous         2.2.0
multidict            6.7.0
pip                  25.1.1
platformdirs         4.4.0
propcache            0.4.0
pydantic             2.12.0
pydantic_core        2.41.1
requests             2.32.5
requests-cache       1.2.1
...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes GrandMoff100/HomeAssistantAPI#225

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.

…errors

Co-authored-by: GrandMoff100 <51765903+GrandMoff100@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix validation errors for Service fields after upgrade Add app selector type to fix HA 2026.x service field validation errors Mar 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants