Skip to content

Commit b5f7b9e

Browse files
craigbarrattraman325
authored andcommitted
added release_history with new changes; create new limitations section
1 parent 4ca8e17 commit b5f7b9e

File tree

5 files changed

+94
-9
lines changed

5 files changed

+94
-9
lines changed

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Contents
2020
tutorial
2121
reference
2222
contributing
23+
release_history
2324
useful_links
2425

2526
.. |GitHub Release| image:: https://img.shields.io/github/release/custom-components/pyscript.svg?style=for-the-badge

docs/overview.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ implemented in a seamless Pythonic manner, such as binding of variables
3535
to states and functions to services. Pyscript supports imports, although
3636
by default the valid import list is restricted for security reasons
3737
(there is a configuration option ``allow_all_imports`` to allow all
38-
imports). Pyscript supports all language features except generators and
39-
``yield``. Pyscript provides a handful of additional built-in functions
40-
that connect to HASS features, like logging, accessing state variables
41-
as strings (if you need to compute their names dynamically), sleeping
42-
and waiting for triggers.
38+
imports). Pyscript supports almost all Python language features except
39+
generators, ``yield`` and user-defined function decorators
40+
(see `language limitations <reference.html#language-limitations>`__).
41+
Pyscript provides a handful of additional built-in functions that connect
42+
to HASS features, like logging, accessing state variables as strings
43+
(if you need to compute their names dynamically), sleeping and waiting
44+
for triggers.
4345

4446
Pyscript also provides a kernel that interfaces with the Jupyter
4547
front-ends (eg, notebook, console and lab). That allows you to develop

docs/reference.rst

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ to this that in a ``@state_trigger`` expression, undefined state variables will
137137

138138
Two virtual attribute values are available when you use a variable directly as ``DOMAIN.entity.attr``
139139
or call ``state.get("DOMAIN.entity.attr")``:
140+
140141
- ``last_changed`` is the last UTC time the state value was changed (not the attributes)
141142
- ``last_updated`` is the last UTC time the state entity was updated
142143

@@ -661,7 +662,8 @@ level will not appear in the log. Each log message function uses a log name of t
661662
custom_components.pyscript.file.FILENAME.FUNCNAME
662663
663664
where ``FUNCNAME`` is the name of the top-level Python function (e.g., the one called by a trigger
664-
or service), defined in the script file ``FILENAME.py``. See the XXXX
665+
or service), defined in the script file ``FILENAME.py``. See the `Global Context <#global-context>`__
666+
section to see the logging path for other cases.
665667

666668
That allows you to set the log level for each Python top-level function separately if necessary.
667669
That setting also applies to any other Python functions that the top-level Python function calls.
@@ -1296,3 +1298,42 @@ With this in place, ``state.persist()`` will be called every time this script is
12961298
``pyscript.last_light_on`` state variable state will persist between HASS restarts. If ``state.persist``
12971299
is not called on a particular state variable before HASS stops, then that state variable will not be
12981300
preserved on the next start.
1301+
1302+
Language Limitations
1303+
^^^^^^^^^^^^^^^^^^^^
1304+
1305+
Pyscript implements a Python interpreter in a fully-async manner, which means it can run safely in the
1306+
main HASS event loop.
1307+
1308+
The language coverage is relatively complete, but it's quite possible there are discrepancies with Python
1309+
in certain cases. If so, please report them.
1310+
1311+
Here are some areas where pyscript differs from real Python:
1312+
1313+
- The pyscript-specific function names and state names that contain a period are treated as plain
1314+
identifiers that contain a period, rather than an attribute (to the right of the period) of an object
1315+
(to the left of the period). For example, while ``pyscript.reload`` and ``state.get`` are functions, ``pyscript``
1316+
and ``state`` aren't defined. However, if you set ``pyscript`` or ``state`` to some value (ie: assign them
1317+
as a variable), then ``pyscript.reload`` and ``state.get`` are now treated as accessing those attributes
1318+
in the ``pyscript`` or ``state`` object, rather than calls to the builtin functions, which are no longer
1319+
available. That's similar to regular Python, where if you set ``bytes`` to some value, the ``bytes.fromhex``
1320+
function is no longer available.
1321+
- Since pyscript is async, it detects whether functions are real or async, and calls them in the
1322+
correct manner. So it's not necessary to use ``async`` and ``await`` in pyscript code - they are optional.
1323+
- All pyscript functions are async. So if you call a Python module that takes a pyscript function as
1324+
a callback argument, that argument is an async function, not a normal function. So a Python module
1325+
won't be able to call that pyscript function unless it uses ``await``, which requires that function to
1326+
be declared ``async``. Unless the Python module is designed to support async callbacks, it is not
1327+
currently possible to have Python modules and packages call pyscript functions. The workaround is
1328+
to move your callbacks from pyscript and make them native Python functions; see `Importing <#importing>`__.
1329+
1330+
A handful of language features are not supported:
1331+
1332+
- generators and the ``yield`` statement; these are difficult to implement in an interpreter.
1333+
- function decorators, beyond the builtin ones, are not yet supported. If there is interest, support
1334+
for function decorators could be added. Additionally, the builtin function decorators aren't
1335+
functions that can be called and used in-line. There is a feature request to add this.
1336+
1337+
Pyscript can call Python modules and packages, so you can always write your own native Python code
1338+
(eg, if you need a generator or other unsupported feature) that can be called by psycript
1339+
(see `Importing <#importing>`__ for how to create and import native Python modules in pyscript).

docs/release_history.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Release History
2+
===============
3+
4+
The releases and releae notes are available on `GitHub <https://github.com/custom-components/pyscript/releases>`__.
5+
Use HACS to install different versions of pyscript.
6+
7+
You can also install the master (head of tree) version from GitHub, either using HACS or manually.
8+
9+
The latest release is 0.32, released on October 21, 2020. Here is the `stable documentation <https://hacs-pyscript.readthedocs.io/en/stable>`__
10+
for that release.
11+
12+
Since that release, the master (head of tree) version in GitHub has several new features and bug fixes.
13+
Here is the master `latest documentation <https://hacs-pyscript.readthedocs.io/en/latest>`__.
14+
15+
The new features since 0.32 in master include:
16+
17+
- Pyscript state variables (entity_ids) can be persisted across pyscript reloads and HASS restarts,
18+
from @swazrgb and @dlashua (#48).
19+
- The ``hass`` object is available in all pyscript global contexts if the ``hass_is_global`` configuration parameter
20+
is true (default false). This allows access to HASS internals that might not be otherwise exposed by pyscript.
21+
Use with caution. PR #51.
22+
- Improvements to UI config flow, including allows parameters to be updated, and the UI reload now works the same
23+
as the ``pyscript.reload`` service call, submitted by @raman325 (#53)
24+
- State variables now support virtual attributes last_changed and last_updated for the UTC time when state values
25+
or any attribute was last changed.
26+
- ``@state_trigger`` and ``task.wait_until`` now have an optional ``state_hold`` duration in seconds that requires
27+
the state trigger to remain true for that period of time. The trigger occurs after that time elapses. If the state
28+
trigger changes to false before the time expires, the process of waiting for a new trigger starts over.
29+
- ``@time_active`` now has an optional ``hold_off`` duration in seconds, which ignores a new trigger if the last
30+
one happened within that time. Can be used for rate limiting or debouncing. Also, ``@time_active`` can now take
31+
zero time range arguments, in case you want to just specify ``hold_off``.
32+
- Added inbound ``context`` variable to trigger functions and support optional ``context`` setting on state,
33+
event firing and service calls. Proposal and PR by @dlashua (#50, #60).
34+
- Logbook now supported using ``context`` and informational message based on trigger type. Proposal and PR by
35+
@dlashua (#50, #62).
36+
37+
The bug fixes since 0.32 in master include:
38+
39+
- Jupyter autocomplete now works on multiline code blocks.
40+
- Improved error message reporting for syntax errors inside f-strings.
41+
- Fixed incorrect global context update on calling module that, in turn, does a callback (#58)

docs/useful_links.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
Useful Links
22
============
33

4-
- `Documentation <https://hacs-pyscript.readthedocs.io/en/latest>`__
4+
- `Documentation stable <https://hacs-pyscript.readthedocs.io/en/stable>`__: latest release
5+
- `Documentation latest <https://hacs-pyscript.readthedocs.io/en/latest>`__: current master in GitHub
56
- `Issues <https://github.com/custom-components/pyscript/issues>`__
67
- `Wiki <https://github.com/custom-components/pyscript/wiki>`__
7-
- `GitHub repository <https://github.com/custom-components/pyscript>`__
8-
(please add a star if you like pyscript!)
8+
- `GitHub repository <https://github.com/custom-components/pyscript>`__ (please add a star if you like pyscript!)
99
- `Jupyter notebook
1010
tutorial <https://nbviewer.jupyter.org/github/craigbarratt/hass-pyscript-jupyter/blob/master/pyscript_tutorial.ipynb>`__

0 commit comments

Comments
 (0)