This experimental project offers a solution to enhance PyScript script development for Home Assistant by providing autocomplete functionality in development environments.
- PyScript Objects Mocking: Enhances autocomplete for PyScript objects in IDEs.
- Class Generation for Services: Auto-generates Python classes for Home Assistant services, including methods and documentation.
- Sensor Class Generation: Creates classes for Home Assistant sensors with relevant attributes.
- Method Generation For Sensors: Supports
sensor.method()
generation for service calls with target - IDE-Only Operation: Operates exclusively within IDEs, not affecting PyScript or Home Assistant functionality.
- Update PyScript Configuration: Enable
allow_all_imports
andhass_is_global
in your PyScript configuration - Configure PyScript: Add the following to your PyScript configuration in
configuration.yaml
- add to pyscript configuration
apps: pyscript_autocomplete:
- Copy the
apps/pyscript_autocomplete
folder to your PyScript directory.
- Generate Autocomplete Data: Use the Home Assistant UI to call the
pyscript.autocomplete_generator
service. - Integrate with Local Project: add
pyscript/modules
as source root in your IDE. - Import in PyScript Files: In any PyScript file, add the line
from pyscript_mock import *
for autocomplete functionality.
exclude:
A list of regular expressions used to exclude specific services, sensors, and attributes. By default, this list is empty, meaning nothing is excluded.include:
A list of regular expressions to specifically include certain services, sensors, and attributes. By default, all are included.
Example:
apps:
pyscript_autocomplete:
exclude:
- person\.test\.friendly_name
include:
- sensor\.
- homeassistant\.turn_.*
- person
- Incompatibility with identifiers that are invalid in Python (e.g., starting with a number).
- Use only
from pyscript_mock import *
. Importing specific classes will lead to errors, as these classes do not exist in PyScript runtime. - In PyScript runtime,
sensor.some_sensor_id
becomes aStateVal
state object, representing the current value of the sensor.# This code will not work @state_trigger(sensor.some_sensor_id) def test(context: Context, var_name: str, value: str, **kwargs): # Correct code @state_trigger("sensor.some_sensor_id") def test(context: Context, var_name: str, value: str, **kwargs):
- If custom-components/pyscript#555 is accepted, it will be possible to use:
@state_trigger(sensor.some_sensor_id.entity_id) @state_trigger(f"{sensor.some_sensor_id.entity_id}>10") def test(context: Context, var_name: str, value: str, **kwargs):
- If custom-components/pyscript#555 is accepted, it will be possible to use: