Bot releases are hidden (Show)
The 1.6.1 release fixes auto-reload, which was broken in the 1.6.0 release. See #622.
Published by craigbarratt 3 months ago
The 1.6.0 release supports HASS 2024.7.
This release has several updates and bug fixes.
async with
without target (see #581 and PR #581 from @dmamelin)Thanks to everyone who contributed PRs and reported issues.
Enjoy!
Published by craigbarratt about 1 year ago
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:
limit
keyword timeout argument (when blocking=True
), since it was removed in HASS 2023.7.translations/de.json
language file (see #462 from @anwirs).or
now returns False
not 0 when subexpressions are False
(see issue #469 from @redlefloh).Event
following change to 2023.8 beta (see #500 from @rccoleman).watchdog
module to 2.3.1, which matches the required version in the folder_watcher
integration in 2023.7.Thanks to everyone who contributed PRs and reported issues.
Enjoy!
Published by craigbarratt over 1 year ago
The 1.4.0 release supports the HASS 2023.3 release.
This release has several bug fixes:
and
) return correct type, not integer (see #335); reported by @ccapndave.kwargs
when state_hold != None
(see #374, #382); reported by @jkrasinger and PR by @ALERTua.*list
(see #420); reported by @fovea1959.comm_open
, comm_msg
and comm_close
messages (see #390); reported by @tms320.@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.translations/sk.json
(see #441); PR by @misa1515.functools
to ALLOWED_IMPORTS
(see #432); requested by @oxan.watchdog
module to 2.2.1, which matches the required version in the folder_watcher
integration in 2023.6.README.md
to correct HACS URL (see #348); PR by @wrt54g).Enjoy!
Published by craigbarratt over 2 years ago
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:
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!
Published by craigbarratt over 3 years ago
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!
Published by craigbarratt over 3 years ago
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:
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).services.yaml
with additional service fields, adopting the new service descriptions in 2021.3.0, submitted by @raman325 (see #174, #176).payload_obj
to list of optional trigger kwargs; also fixed unexpected keyword arg exception reporting; reported by @Beiri22 (see #170).Enjoy!
Published by craigbarratt over 3 years ago
The 1.3.0 release contains several cool new features and various bug fixes.
New features since 1.2.1 include:
@state_trigger
, @time_trigger
, @event_trigger
or @mqtt_trigger
) per function are now supported. See #157.@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.@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
.@pyscript_executor
decorator, which does same thing as @pyscript_compile
and additionally wraps the resulting function with a call to task.executor
. See #71.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.@pyscript_compile
and @pyscript_executor
to enforce there are no args or kwargs.Breaking changes since 1.2.1 include:
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:
@state_trigger
with only a .old
variable, which previously never triggered; reported by stigvi.global_ctx="*"
and reload via Configuration -> Integrations UI menu now start triggers, reported by Fabio C.locals()
, exec()
and eval()
so that various scoping scenarios work correctly.lineno
is inside code_list[]
; with lambda function or eval it might not be.Enjoy!
Published by craigbarratt over 3 years ago
The 1.2.1 release contains several bug fixes:
@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.Enjoy!
Published by craigbarratt over 3 years ago
The 1.2.0 release contains some cool new features and some bug fixes.
New features since 1.1.0 include:
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.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.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.@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.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.croniter
to 1.0.2.@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:
task.unique()
; reported by @dlashua (#117).@service
function definitions (ie, with the same name) now correctly register the service, reported by @wsw70; see #121.@time_active
argument, by @dlashua; see #118.scripts
subdirectory is now recursively traversed for requirements.txt
files.global
.allow_all_imports
or hass_is_global
change; see #74.__del__
works; reported by @dlashua; see #146.open()
now set encoding=utf-8
so Windows platforms use the correct encoding; see #145.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()
."scripts/**"
to REQUIREMENTS_PATHS
, so deeper directories are searched.Thanks to @dlashua for proposing, implementing and testing several new features in this release.
Enjoy!
Published by craigbarratt almost 4 years ago
The 1.1.0 release contains some cool new features and some bug fixes.
New features:
@mqtt_trigger
supports triggering off mqtt events, including an optional trigger expression, by @dlashua (#98, #105)..py
files below the pyscript/scripts
directory are autoloaded, recursively, allowing you to arrange your scripts in sub-directories (or deeper) (#97).pyscript.reload
only reloads changed files (changed contents, mtime, or an app's yaml configuration). All files in an app or module are reloaded if any one has changed, and any script, app or module that imports a changed modules (directly or indirectly) is also reloaded. Setting the optional global_ctx
service parameter to *
forces reloading all files (which is the behavior in 1.0.0 and earlier). See #106.#
is skipped, which is an in-place way of disabling a specific script, app or directory tree; think of this as "commenting" the script or directory (#97).state_hold_false=None
optional period in seconds to @state_trigger()
and task.wait_until()
. This requires the trigger expression to be False
for at least that period (including 0) before a successful trigger. Setting this optional parameter makes state triggers edge triggered (ie, triggers only on transition from False
to True
), instead of the default level trigger (ie, only has to evaluate to True
). Proposed by @tchef69 (#89), with suggestions from @dlashua (#95).@time_trigger
now supports a "shutdown"
trigger, which occurs on HASS shutdown or whenever the trigger function is no longer referenced (eg: during reload, or redefinition in Jupyter), proposed by @dlashua (#103).task.unique
now allows multiple names to be "owned" by each task to support cases where you need to be exclusive against multiple other functions; provided by @dlashua.del
and a new function state.delete()
can delete state variables and state variable attributes.tests/requirements_test.txt
.Breaking changes:
pyscript.reload
service only reloads changed files; prior behavior of reloading all files can be requested by setting the optional global_ctx
service parameter to *
.trigger_time
trigger function argument is now set to "startup"
for a startup trigger, rather than None
. This was done to be consistent with the new shutdown
trigger, which calls the trigger function with trigger_time="shutdown"
. If you use trigger_time is None
to detect a startup trigger, you'll need to change that to trigger_time == "startup"
(see #103).The bug fixes include:
MappingProxyType
recursion error inside HASS; reported by @github392 (#87).state.get_attr
was missing an await
, which causes an exception; it now works correctly, but please use state.getattr
since the old function will be removed in a future release; reported and fixed by @dlashua (#88).packaging
module is installed if not found, since certain HASS configurations might not include it; fixed by @raman325 (#90, #91).Thanks to @dlashua for adding @mqtt_trigger
and multiple names in task.unique()
, proposing several new features, as well as bug fixes and testing, and @raman325 for some bug fixes.
Enjoy!
Published by craigbarratt almost 4 years ago
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.
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)last_changed
and last_updated
for the UTC time when state values or any attribute was last changed.DOMAIN.name.attr = value
. An equivalent new function state.setattr()
allows a specific attribute to be set.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
.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).pyscript.reload
service call, from @raman325 (#53)context
variable to trigger functions and support optional context
setting on state, event firing and service calls. Proposal and PR from @dlashua (#50, #60).context
and informational message based on trigger type. Proposal and PR from @dlashua (#50, #62).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).global_ctx
that specifies just that global context is reloaded, eg: global_ctx="file.my_scripts"
. Proposed by @dlashua (#63).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).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.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).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.
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!
Published by craigbarratt almost 4 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 or
ed together.allow_all_imports
now take effect on reload.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!
Published by craigbarratt about 4 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:
task.unique()
doesn't kill itself if the same task previously called itThanks to @raman325 for developing the config flow support, and to @dlashua for discovering and reporting all those bugs and providing concise failing examples.
Enjoy!
Published by craigbarratt about 4 years ago
The 0.30 release contains a number of new features, and several bug fixes.
The main new features are:
<config>/pyscript
directorypyscript.config
that allows access to yaml
configuration settingstask.executor()
for functions that block (eg, doing I/O) or have long running timeswith
, async for
, lambda
and named expressionscroniter
package for cron functionsBreaking changes:
task.unique()
now only applies within the current global context; the same name used in other global contexts will not be affectedNameError
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 definedInfrastructure:
black
, isort
, flake8
and pytest
black
/flake8
/isort
pytest
setupBug fixes include:
del
works correctly for non-locally scoped variablesThanks 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!
Published by craigbarratt about 4 years ago
The 0.21 release contains a number of new features, and several bug fixes.
The main new features are:
allow_all_imports
can be set to true
to allow any package to be imported (thanks to @basnijholt, #8)@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)state.names()
to get a list of all entity ids for a given domain, or all if a domain is not specified (#12)state.get_attr()
to get all the attributes (in a dict
) for a state variableprint()
as an alias for log.debug()
; it currently only supports a single argumentOne 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:
Enjoy!
Published by craigbarratt about 4 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!
Published by craigbarratt about 4 years ago
Fixed incorrect filename key in hacs.json that prevented download.
Published by craigbarratt about 4 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.