Skip to content

dmamelin/pyscript_autocomplete

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 

Repository files navigation

Home Assistant PyScript Autocomplete

This experimental project offers a solution to enhance PyScript script development for Home Assistant by providing autocomplete functionality in development environments.

Features

  • 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. image

Installation

  • Update PyScript Configuration: Enable allow_all_imports and hass_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.

Advanced Configuration

  • 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

Notes

  • 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 a StateVal 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):

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published