Pyscript Versions Save

Pyscript adds rich Python scripting to HASS

0.32

3 years ago

The 0.32 release contains a couple of new features and one important bug fix.

New features:

  • @state_trigger now supports just a state variable name string argument, which triggers on any change. This replaces the old confusing "True or domain.entity_id" form, although that still works.
  • @state_trigger can now take multiple arguments, and any argument can be a list of string expressions or string state variable names (trigger on any change). All the conditions are logically ored together.
  • Updates to the configuration setting allow_all_imports now take effect on reload.
  • Improved error reporting during config flow.

The bug fix is to clean up a task to avoid a stall during HASS restart.

Thanks to @raman325 for supporting config changes on reload and improved error reporting in config flow.

Enjoy!

0.31

3 years ago

The 0.31 release contains one significant new feature and several bug fixes.

The new feature is config flow support, which allows setup of pyscript (including allow_all_imports) from the UI, while still allowing optional app configuration via yaml. Also, __name__ is now supported so modules, packages or apps can know their name.

On the infrastructure side, pylint is now included in the pre-commit, push and PR flows, and all tests now use pytest_homeassistant_custom_component instead of pytest_homeassistant.

Bug fixes include:

  • global variable binding is done at run time
  • class methods use the caller's execution context
  • trigger actions now execute in the their own execution context
  • task.unique() doesn't kill itself if the same task previously called it
  • module and package functions use their own global symbol table, instead of caller's

Thanks to @raman325 for developing the config flow support, and to @dlashua for discovering and reporting all those bugs and providing concise failing examples.

Enjoy!

0.30

3 years ago

The 0.30 release contains a number of new features, and several bug fixes.

The main new features are:

  • support for apps and importable modules and packages below the <config>/pyscript directory
  • support for trigger functions as closures, allowing factory functions to create multiple similar trigger functions
  • added a variable pyscript.config that allows access to yaml configuration settings
  • added task.executor() for functions that block (eg, doing I/O) or have long running times
  • added support for with, async for, lambda and named expressions
  • use the croniter package for cron functions
  • improved exception handling and reporting

Breaking changes:

  • task.unique() now only applies within the current global context; the same name used in other global contexts will not be affected
  • accessing an undefined state variable now throws a NameError exception, instead of returning None, except in @state_trigger or @state_active, where undefined state variables, attributes or the .old value will still evaluate to None if not defined

Infrastructure:

  • moved documentation from README to hacs-pyscript.readthedocs.io and added more material
  • added precommit checks for black, isort, flake8 and pytest
  • set line-length to 109 for black/flake8/isort
  • revamped pytest setup
  • improved test coverage

Bug fixes include:

  • variable scoping in function closures now works correctly
  • fixed augmented assignments
  • list/set/dict comprehension looping vars are now in implicitly nested scope
  • del works correctly for non-locally scoped variables
  • sunrise and sunset times now correct for dates other than today

Thanks to @fleXible for several PRs (adding croniter, fixing sunset/sunrise, revamping test infrastructure, refactoring and precommits, among others) and @dlashua for extensive testing, various bug reports and feature requests.

Enjoy!

0.21

3 years ago

The 0.21 release contains a number of new features, and several bug fixes.

The main new features are:

  • language support for classes, list/dict/set comprehensions, and assert
  • an optional configuration parameter allow_all_imports can be set to true to allow any package to be imported (thanks to @basnijholt, #8)
  • "startup" is now a valid @time_trigger time_spec, which allows a function to be called on startup and at additional specified times (#7)
  • @task_unique is a new decorator with the same arguments as task.unique() (#1)
  • added state.names() to get a list of all entity ids for a given domain, or all if a domain is not specified (#12)
  • added state.get_attr() to get all the attributes (in a dict) for a state variable
  • added print() as an alias for log.debug(); it currently only supports a single argument
  • autocomplete in Jupyter now includes Python keywords

One breaking change is that assigning to a state variable (HASS entity id) now preserves its existing attributes (previously, setting a state variable would delete its attributes). The state.set() function can be used to optionally overwrite or remove all attributes, or to set specific attributes while preserving others.

Bug fixes include:

  • tuple assignments are fixed (fixes #14, #15)
  • charset encoding on Jupyter messages is now utf-8 (fixes hass-puscript-jupyter #10)

Enjoy!

0.20

3 years ago

Pyscript 0.20 is a significant release that supports the Jupyter frontends (eg, notebook, console, lab). This allows fully interactive development and testing of pyscript functions, services, triggers and automation logic. Auto-completion with TAB is supported. See this README.md for more information.

To use Jupyter with pyscript you need to install a kernel shim from the hass-pyscript-jupyter repository.

Other new pyscript features include support for eval(), exec(), globals(), locals() and exceptions (try, except and raise). Error reporting and handling have been improved.

One small change that isn't backward compatible is that the logger path for pyscript has changed from homeassistant.components.pyscript to custom_components.pyscript. Also, the sub-path for pyscript functions has changed. To specify the logging level of a pyscript function FUNCNAME in a pyscript file FILE (without the .py extension), the logger path used in the logger configuration is now:

custom_components.pyscript.file.FILENAME.FUNCNAME

(In 0.11 it was homeassistant.components.pyscript.func.FUNCNAME, which is ambiguous if the same function name is used in different pyscript files.)

There are also a few bug fixes, including an issue that caused task.unique() to not terminate the specified task after the first time.

Enjoy!

0.11

3 years ago

Fixed incorrect filename key in hacs.json that prevented download.

0.10

3 years ago

Initial release of pyscript as a custom component in HACS. Thanks to @ludeeus for HACS and the help in setting up this repository.

This release is broken. Please use >= 0.11 instead.