diff --git a/custom_components/pyscript/stubs/generator.py b/custom_components/pyscript/stubs/generator.py index 40dd6dbf..5bf3234e 100644 --- a/custom_components/pyscript/stubs/generator.py +++ b/custom_components/pyscript/stubs/generator.py @@ -260,7 +260,8 @@ async def _create_service_function( field_nodes = [ _ServiceField( name="entity_id", - annotation=self._name("str"), + # a service target takes one entity id or a list of them + annotation=ast.parse("str | list[str]", mode="eval").body, required=True, default=None, description="Entity ID", diff --git a/tests/test_stubs.py b/tests/test_stubs.py index c11670c4..002bf357 100644 --- a/tests/test_stubs.py +++ b/tests/test_stubs.py @@ -140,7 +140,7 @@ async def fake_service_descriptions(_hass: HomeAssistant) -> dict[str, dict[str, assert "class _light_state(StateVal)" in generated_content assert "lamp: _light_state" in generated_content assert "def blink(self, *, brightness: int, speed" in generated_content - assert "def blink(*, entity_id: str, brightness: int, speed:" in generated_content + assert "def blink(*, entity_id: str | list[str], brightness: int, speed:" in generated_content assert "Blink the light once." in generated_content assert "Literal" in generated_content assert "'slow'" in generated_content @@ -464,7 +464,7 @@ async def fake_service_descriptions(_hass: HomeAssistant) -> dict[str, dict[str, assert send["footer"] == ("str | None", "None") # ...a field named like the implicit target argument is skipped... assert send_to == { - "entity_id": ("str", None), + "entity_id": ("str | list[str]", None), "blocking": ("bool", "..."), "return_response": ("bool", "..."), }