Skip to content

Pyscript 1.0.0 release

Compare
Choose a tag to compare
@craigbarratt craigbarratt released this 09 Nov 20:20
· 340 commits to master since this release

The 1.0.0 release contains quite a few new features and some bug fixes. Given the number of new features, I decided to bump the version to 1.0.0 and switch to the more normal version number format.

New features

  • Pyscript state variables (entity_ids) can be persisted across pyscript reloads and HASS restarts, from @swazrgb and @dlashua (#48).
  • Entities domain.entity now support a virtual method service (eg, domain.entity.service()) that calls the service domain.service for any service that has an entity_id parameter, with that entity_id set to domain.entity. Proposed by @dlashua (#64).
  • @state_trigger now supports triggering on an attribute change with "domain.entity.attr" and any attribute change with "domain.entity.*", from @dlashua (#82)
  • State variables now support virtual attributes last_changed and last_updated for the UTC time when state values or any attribute was last changed.
  • State variable attributes can be set by direct assignment, eg: DOMAIN.name.attr = value. An equivalent new function state.setattr() allows a specific attribute to be set.
  • State variable values (eg, from domain.entity or state.get()) now include attributes that can be accessed after they are assigned to another, normal, variable.
  • @state_trigger and task.wait_until now have an optional state_hold duration in seconds that requires the state trigger to remain true for that period of time. The trigger occurs after that time elapses. If the state trigger changes to false before the time expires, the process of waiting for a new trigger starts over.
  • @time_active now has an optional hold_off duration in seconds, which ignores a new trigger if the last one happened within that time. Can be used for rate limiting or debouncing. Also, @time_active can now take zero time range arguments, in case you want to just specify hold_off.
  • The hass object is available in all pyscript global contexts if the hass_is_global configuration parameter is true (default false). This allows access to HASS internals that might not be otherwise be exposed by pyscript. Use with caution (#51).
  • Improvements to UI config flow, including allowing parameters to be updated, and the UI reload now works the same as the pyscript.reload service call, from @raman325 (#53)
  • Added inbound context variable to trigger functions and support optional context setting on state, event firing and service calls. Proposal and PR from @dlashua (#50, #60).
  • Logbook now supported using context and informational message based on trigger type. Proposal and PR from @dlashua (#50, #62).
  • Required Python packages can be specified in requirements.txt files at the top-level pyscript directory, and each module's or app's directory. Those files are read and any missing packages are installed on HASS startup and pyscript reload. If a specific version of a package is needed, it can be pinned using the format package_name==version. Contributed by @raman325 (#66, #68, #69, #70, #78).
  • The reload service now takes an optional parameter global_ctx that specifies just that global context is reloaded, eg: global_ctx="file.my_scripts". Proposed by @dlashua (#63).
  • The state.get_attr() function has been renamed state.getattr(). The old function is still available and will be removed in some future release (it logs a warning when used).
  • VSCode connections to pyscript's Jupyter kernel now work. Two changes were required: VSCode immediately closes the heartbeat port, which no longer causes pyscript to shut down the kernel. Also, stdout messages are flushed prior to sending the execute complete message. This is to ensure log and print messages get displayed in VSCode. One benign but unresolved bug with VSCode is that when you connect to the pyscript kernel, VSCode starts a second pyscript Jupyter kernel, before shutting that second one down.
  • Service calls now accept blocking and limit parameters. The default behavior for a service call is to run it in the background, but using blocking=True will force a task to wait up to limit seconds for the service call to finish executing before continuing. Contributed by @raman325 (#85).

Breaking change due to bug fix

The @state_trigger expression is only evaluated when at least one of the state variables or attributes specifically mentioned in the expression have changed. This was fixed by @dlashua in #82, add see issue #73. Previously, any change to the state variable (eg, an attribute) would cause the @state_trigger expression to be evaluated, even if that attribute didn't appear in the expression. Although this is a bug fix, it does change when @state_trigger might cause a trigger. For example, if you use the trigger-on-any change form @state_trigger("domain.entity"), prior to 1.0.0 it would trigger on any state value change or any attribute change. In 1.0.0 and later, it will only trigger on a state value change. Also, if you used this form to make sure domain.entity had actually changed to new_value:

@state_trigger("domain.entity == 'new_value' and domain.entity.old != 'new_value'")

that will still work in 1.0.0, but confirming domain.entity.old is not new_value is no longer necessasry, and that 2nd clause can be safely removed.

Bug Fixes

  • Jupyter autocomplete now works on multiline code blocks.
  • Improved error message reporting for syntax errors inside f-strings.
  • Fixed incorrect global context update on calling module that, in turn, does a callback (#58).
  • task.wait_until no longer silently ignores unrecognized keyword arguments (#80).
  • task.wait_until incorrectly ignored the keyword optional state_check_now argument (#81).

Thanks to @dlashua, @raman325 and @swazrgb for all their contributions to this release.

Enjoy!