Skip to content

Pyscript 1.3.0 release

Compare
Choose a tag to compare
@craigbarratt craigbarratt released this 25 Feb 06:18
· 161 commits to master since this release

The 1.3.0 release contains several cool new features and various bug fixes.

New features since 1.2.1 include:

  • Multiple trigger decorators (@state_trigger, @time_trigger, @event_trigger or @mqtt_trigger) per function are now supported. See #157.
  • Trigger decorators (@state_trigger, @time_trigger, @event_trigger or @mqtt_trigger) support an optional kwargs keyword argument that can be set to a dict of keywords and values, which are passed to the trigger function. See #157.
  • The @service decorator now takes one or more optional string arguments to specify the name of the service, of the form "DOMAIN.SERVICE". The @service decorator can also be used multiple times as an alternative to using multiple arguments. The default continues to be pyscript.FUNC_NAME.
  • Added @pyscript_executor decorator, which does same thing as @pyscript_compile and additionally wraps the resulting function with a call to task.executor. See #71.
  • Added watch keyword argument to @state_trigger, which allows the list or set of state variables that are monitored to be specified. Normally that list is extracted from the @state_trigger expression.
  • Errors in trigger-related decorators (eg, wrong arguments, unrecognized decorator type) raise exceptions rather than logging an error.
  • Types of keyword arguments to trigger decorators are now checked and exceptions raised if incorrect.
  • Added error checking for @pyscript_compile and @pyscript_executor to enforce there are no args or kwargs.
  • Enabled GitHub discussions and added links to it; see #167.

Breaking changes since 1.2.1 include:

  • Since decorator errors now raise exceptions, if you had a script with such an error that otherwise works, that script will now give an exception and fail to load. The error should be self-explanatory, and it's good to know so you can fix it.
  • Since an exception is now raised if you call a function with an invalid keyword argument (ie, one not included in the function's argument definition), if you previously had a misspelled keyword argument that was silently ignored, you will now get an exception. It's good to know that is the case, and it should be easy to fix.
  • The use of pyscript.config["apps"][YOUR_APP] to get application configuration is still available but now deprecated. The apps entry in pyscript.config will be removed in a future release. This is to prevent wayward applications from seeing configuration settings for other apps. The new pyscript.app_config variable should be used instead - it is set to pyscript.config["apps"][YOUR_APP] for each app.

Bug fixes since 1.2.1 include:

  • Fixed @state_trigger with only a .old variable, which previously never triggered; reported by stigvi.
  • Reload with global_ctx="*" and reload via Configuration -> Integrations UI menu now start triggers, reported by Fabio C.
  • Fixed subscripts when running python 3.9.x.
  • Timeouts that implement time triggers might infrequently occur a tiny time before the target time. A fix was added to do an additional short timeout when there is an early timeout, to make sure any time trigger occurs at or shortly after the target time (and never before).
  • Fixes to locals(), exec() and eval() so that various scoping scenarios work correctly.
  • When exception text is created, ensure lineno is inside code_list[]; with lambda function or eval it might not be.
  • An exception is raised when a function is called with unexpected keyword parameters that don't have corresponding keyword arguments (however, the trigger parameter names are excluded from this check, since trigger functions are allowed to have any subset of keyword arguments).
  • Non-local keyword arguments in inner functions are now correctly resolved to their outer scope; see #163
  • Trigger on any state change now matches state names with leading digits; see #165

Enjoy!