Add IDE stubs generator service, docs, and tests #771
Merged
+1,231
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is a reworked and improved version of pyscript_autocomplete.
Better docstrings and more accurate type definitions for the Pyscript runtime and for Home Assistant domains, services, and entities with attributes.
How it works:
pyscript.generate_stubs
reads the HA entity registry, skips disabled entries, and records each entity along with its attributes. Attributes with names that aren’t valid Python identifiers are listed and excluded from the final code._domain_state
class (subclass ofStateVal
) is created with the discovered attributes. Then a domain class is built where each entity is declared as a field of that state class.async_get_all_descriptions
, all HA service definitions are extracted. The generator converts selectors into python types, handles required/default fields and descriptions, and generates functions both at the domain level (as@staticmethod
) and on the entity state class (if the service supports a target).ast.unparse
.pyscript_builtins.py
and writes the generated module to /pyscript/modules/stubs/.from stubs import
andfrom stubs.* import
statements are ignored at runtime. Theoretically this could be a breaking change, but in practice, no one keeps real code in stubs.Example for
time
domain:In my HA installation, the generator produced about 5,900 lines of code, and it works perfectly.

Tested with PyCharm, VS Code, and Studio Code Server.