Skip to content

Stubs: accept a list of entity ids for a service's entity_id (#814) - #904

Merged
craigbarratt merged 1 commit into
custom-components:masterfrom
HoneyBearTech:stubs-entity-id-list-814
Nov 20, 2026
Merged

craigbarratt merged 1 commit into
custom-components:masterfrom
HoneyBearTech:stubs-entity-id-list-814

Conversation

@HoneyBearTech

@HoneyBearTech HoneyBearTech commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Refs #814 (fixes item 2 only)

What was wrong
In the generated stubs, the implicit entity_id argument of service functions was typed str. A service target takes one entity id or a list of them, so type checkers flagged code
that passed a list, which works fine.

What I changed
In stubs/generator.py, the implicit entity_id is now typed str | list[str]. I updated the two matching checks in tests/test_stubs.py.

I left out tuple[str] on purpose. Home Assistant's comp_entity_ids treats a tuple as a single item, so a tuple of ids wouldn't work as expected.

The other items in #814

  • Item 1 (duration): the stubs don't type the duration selector at all, so the type isn't too narrow.
  • Item 3 (input_number as ConvertibleToFloat): the issue itself leaves the right design open, so I didn't change it.
  • Item 4 (delay_secs, hold_secs): already float, because their selector uses a fractional step.
  • Items 5 and 6 (webhook_methods default, event_trigger's str_expr): already correct on master.
  • Item 7 (one shared type for color_name): a tidy-up rather than a wrong type, so I didn't change it here.

Testing
tests/test_stubs.py, the full test suite, pylint, mypy and ruff all pass on Python 3.14.

…ents#814)

The static service functions in the generated stubs typed the implicit
entity_id argument as str, but a service target takes one entity id or
a list of them, so passing a list was flagged by type checkers. Type it
as str | list[str].

Signed-off-by: Sean Stoube <31805425+HoneyBearTech@users.noreply.github.com>
@HoneyBearTech HoneyBearTech changed the title stubs: accept a list of entity ids for service targets (#814) Stubs: accept a list of entity ids for a service's entity_id (#814) Nov 19, 2026

@craigbarratt craigbarratt left a comment

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.

Thanks @HoneyBearTech, this looks good, and thanks for working through the other items in #814.

A small note on tuples: HA 2026.11's validators now accept a tuple (or even a set) of entity ids. Older versions don't, so str | list[str] is still the right type.

@craigbarratt
craigbarratt merged commit 8131a78 into custom-components:master Nov 20, 2026
5 checks passed
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