Skip to content

Releases: custom-components/pyscript

Pyscript 1.6.1 release

28 Jul 01:54
Compare
Choose a tag to compare

The 1.6.1 release fixes auto-reload, which was broken in the 1.6.0 release. See #622.

Pyscript 1.6.0 release

27 Jul 00:49
Compare
Choose a tag to compare

The 1.6.0 release supports HASS 2024.7.

This release has several updates and bug fixes.

  • Kwargs in triggers no longer affected by kwargs from previous triggers (see #512 from @rajeee and #516 from @ALERTua)
  • Ignore benign error message when local variables are deleted after list comprehension (PR #535 from @akonradi)
  • Added support for annotated assignment (ast_annassign); (see #537 from @binaryaaron)
  • Added support for positional-only function arguments
  • Fixed DST handling for cron time triggers
  • Add virtual attribute StateVal.entity_id (PR #555 from @dmamelin)
  • Fix for async with without target (see #581 and PR #581 from @dmamelin)
  • Add new webhook trigger (PR #592 from @contagon)
  • Updated croniter version to 2.0.2 (PR #595 from @ALERTua)
  • Support python 3.12 and resolve issue with blocking sunset/sunrise calls (PR #610 from @IgnusG)
  • Doc updates from @rodneybetts (PR #549) and @amckenny (PR #615)
  • Moved watchdog to its own thread to avoid blocking the event loop

Thanks to everyone who contributed PRs and reported issues.

Enjoy!

Pyscript 1.5.0 release

30 Jul 17:29
Compare
Choose a tag to compare

The 1.5.0 release supports the HASS 2023.7 and 2023.8 beta releases, and should be backward compatible with older versions.

This release has several updates and bug fixes:

  • Service calls no longer support the optional limit keyword timeout argument (when blocking=True), since it was removed in HASS 2023.7.
  • Added translations/de.json language file (see #462 from @anwirs).
  • Boolean or now returns False not 0 when subexpressions are False (see issue #469 from @redlefloh).
  • Directly access hass.data[DATA_RESTORE_STATE] to avoid deprecated api; this is a hack and I need a better fix (see #473 from @slomanl1).
  • Added support for service responses (see #495 from @matzman666).
  • Fix import of HASS Event following change to 2023.8 beta (see #500 from @rccoleman).
  • Log warning if user calls time.sleep(), which blocks, and call asyncio.sleep() instead.
  • Bump the required version of the watchdog module to 2.3.1, which matches the required version in the folder_watcher integration in 2023.7.
  • Bump Python to version to 3.11 for tests, and updated various versions of packages.

Thanks to everyone who contributed PRs and reported issues.

Enjoy!

Pyscript 1.4.0 release

04 Apr 23:53
Compare
Choose a tag to compare

The 1.4.0 release supports the HASS 2023.3 release.

This release has several bug fixes:

  • Boolean operators (eg: and) return correct type, not integer (see #335); reported by @ccapndave.
  • Fixed setting of kwargs when state_hold != None (see #374, #382); reported by @jkrasinger and PR by @ALERTua.
  • Decorator function arguments now expand *list (see #420); reported by @fovea1959.
  • Jupyter kernel interface ignores comm_open, comm_msg and comm_close messages (see #390); reported by @tms320.
  • Fix boolean operator truth test (see #438); reported by @Kaptensanders.
  • Fixed unexpected triggers by @event_trigger due to prior trigger variables persisting in the context's symbol table; fixed by ensuring local symbol table is overwritten by default (see #439); reported by @Michael-CGN.
  • Ensure user decorator functions start triggers in correct context (see #428, #457); reported by @j-steve.
  • Added translations/sk.json (see #441); PR by @misa1515.
  • Added functools to ALLOWED_IMPORTS (see #432); requested by @oxan.
  • Bump Python to version to 3.10 for tests, and updated various versions of packages.
  • Bump the required version of the watchdog module to 2.2.1, which matches the required version in the folder_watcher integration in 2023.6.
  • Update README.md to correct HACS URL (see #348); PR by @wrt54g).
  • Fix link to developer docs (see #373); PR by @robertgresock.

Enjoy!

Pyscript 1.3.3 release

09 Mar 19:17
Compare
Choose a tag to compare

The 1.3.3 release supports the HASS 2022.3 release, which has a breaking change related to the interface for entity (state) persistence.
State persistence in pyscript will not work in HASS 2022.3 if you use pyscript versions prior to 1.3.3.

This was reported by @LeszekSwirski and fixed by @dlashua (see #331). Thanks!

This release also bumps the required version of the watchdog module to 2.1.6, which matches the required version in the folder_watcher integration in 2022.3. If you run this version of pyscript with an older version of HASS, you might see a version conflict for watchdog. If so, either upgrade HASS or downgrade pyscript to 1.3.2.

There are a couple of other bug fixes since 1.3.2:

  • Correctly detect inner functions instead of just at top level, reported by @LeszekSwirski (see #263).
  • Ensure once() triggers without a date that have a negative (eg, midnight - 30s) or large (more than 2 days) offset are adjusted so they happen in the next 24 hours. Previously, a negative offset or a large positive offset that were in the past or more than 2 days in the future would never trigger. Reported by @herrfrei (see #330).

Enjoy!

Pyscript 1.3.2 release

10 May 01:41
Compare
Choose a tag to compare

The 1.3.2 release supports the HASS 2021.5.0 release, which changed the astral version and the return values of sun.get_astral_location, which caused sunrise and sunset time triggers to fail.

Thanks to @bob-tm for reporting and tracking down the breaking change. See #203

Enjoy!

Pyscript 1.3.1 release

04 Mar 10:19
Compare
Choose a tag to compare

The 1.3.1 release supports the HASS 2021.3.0 release, which changed the interface for entity services.

Here are the bug fixes since 1.3.0:

  • Fixed identification of entity services (services that have entity_id as a parameter) to be compatible with changes in HASS 2021.3.0. With pyscript 1.3.0 and earlier, the virtual entity (state) methods that call entity services no longer work in HASS 2021.3.0. Reported by @Nxt3 and debugged by @raman325 (see #173, #178).
  • Updated docs and services.yaml with additional service fields, adopting the new service descriptions in 2021.3.0, submitted by @raman325 (see #174, #176).
  • add payload_obj to list of optional trigger kwargs; also fixed unexpected keyword arg exception reporting; reported by @Beiri22 (see #170).

Enjoy!

Pyscript 1.3.0 release

25 Feb 06:18
Compare
Choose a tag to compare

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!

Pyscript 1.2.1 release

09 Feb 10:41
Compare
Choose a tag to compare

The 1.2.1 release contains several bug fixes:

  • Fixed @time_active so that ranges without dates (eg: plain sunrise, sunset or fixed times) work correctly on days after HASS was started. Reported by @markwhibbard; fix confirmed by @markwhibbard and @patrickfnielsen; see #149.
  • lambda functions are now compiled so they are native python lambda functions that can be called from filter, map or anywhere that expects a regular python function. Reported by Greg sj3fk3.
  • Raise an exception when a local variable is used before setting. Previously if a variable of the same name was defined globally, it was incorrectly used instead.
  • Minor documentation fix regarding yaml file includes, submitted by @wsw70; see #153, #154.

Enjoy!

Pyscript 1.2.0 release

01 Feb 00:39
Compare
Choose a tag to compare

The 1.2.0 release contains some cool new features and some bug fixes.

New features since 1.1.0 include:

  • Reload is automatically done whenever a script file, requirements.txt or yaml file below the pyscript folder is modified, created, renamed or deleted, or a directory is renamed, created or deleted; see #74. This uses the watchdog module which is already used by the folder_watcher integration.
  • New functions task.create, task.current_task, task.cancel, task.name2id, task.wait, task.add_done_callback, task.remove_done_callback allow new background (async) tasks to be created, canceled, waited on, and completion callbacks to be added or deleted. Proposed by @dlashua and @valsr; see #112, #130, #143, #144.
  • Added support for now to @time_trigger time specifications, which means the current date and time when the trigger was first evaluated (eg, at startup or when created as an inner function or closure), and remains fixed for the lifetime of the trigger. This allows time triggers of the form once(now + 5min) or period(now, 1hr). Proposed by @wsw70; see #139.
  • Function decorators are now supported. However, the existing trigger decorators are still hardcoded (ie, not available as function calls), and decorators on classes are not yet supported. First implementation by @dlashua; see #43.
  • New function decorator @pyscript_compile compiles a native Python function inside pyscript, which is helpful if you need a regular function (by default all pyscript functions are async coroutines) for task.executor, functions like map or filter, callbacks, or if you have code you want to run at compiled speed (see #71). The function body can't contain any pyscript-specific features, and closure of variables for an inner function that uses @pyscript.compile won't work either, since in pyscript local variables with scope binding are objects, not their native types. Proposed by @dlashua; see #71.
  • A new variable pyscript.app_config is available in the global address space of an app's main file (ie, apps/YOUR_APP.py or apps/YOUR_APP/__init__.py) and is set to the YAML configuration for your app (ie, pyscript.config["apps"][YOUR_APP]). The latter is still available, but is deprecated and the apps entry in pyscript.config will be removed in a future release to prevent wayward applications from seeing configuration settings for other apps.
  • Updated croniter to 1.0.2.
  • Updated docs to explain how secret parameter values can be stored and retrieved from yaml configuration, by @exponentactivity; see #124.
  • Report parsing errors on invalid @time_active arguments; by @dlashua; see #119.
  • task.executor raises an exception when called with a pyscript function.

Breaking changes since 1.1.0 include:

None. However, 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.1.0 include:

  • Fixed shutdown trigger for case where it calls task.unique(); reported by @dlashua (#117).
  • Duplicate @service function definitions (ie, with the same name) now correctly register the service, reported by @wsw70; see #121.
  • Added error message for invalid @time_active argument, by @dlashua; see #118.
  • The scripts subdirectory is now recursively traversed for requirements.txt files.
  • Inner functions and classes (defined inside a function) are added to global symbol table if declared as global.
  • Reload all scripts if global settings allow_all_imports or hass_is_global change; see #74.
  • Methods bound to class instances use weakrefs so that __del__ works; reported by @dlashua; see #146.
  • Pyscript user-defined functions (which are all async) can now be called from native python async code; see #137.
  • Internals that call open() now set encoding=utf-8 so Windows platforms use the correct encoding; see #145.
  • On Windows, python is missing locale.nl_langinfo, which caused startup to fail when the locale-specific days of week were extracted. Now the days of week in time trigger expressions are available on Windows, but only in English; see #145.
  • task.name2id() raises NameError if task name is undefined. Also added kwargs to task.wait().
  • Added "scripts/**" to REQUIREMENTS_PATHS, so deeper directories are searched.
  • Fixed typos in task reaper code, by @dlashua; see #116.
  • Fixed exception on invalid service call positional arguments, reported by @huonw; see #131.

Thanks to @dlashua for proposing, implementing and testing several new features in this release.

Enjoy!