@@ -137,6 +137,7 @@ to this that in a ``@state_trigger`` expression, undefined state variables will
137
137
138
138
Two virtual attribute values are available when you use a variable directly as ``DOMAIN.entity.attr ``
139
139
or call ``state.get("DOMAIN.entity.attr") ``:
140
+
140
141
- ``last_changed `` is the last UTC time the state value was changed (not the attributes)
141
142
- ``last_updated `` is the last UTC time the state entity was updated
142
143
@@ -661,7 +662,8 @@ level will not appear in the log. Each log message function uses a log name of t
661
662
custom_components.pyscript.file.FILENAME.FUNCNAME
662
663
663
664
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.
665
667
666
668
That allows you to set the log level for each Python top-level function separately if necessary.
667
669
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
1296
1298
``pyscript.last_light_on `` state variable state will persist between HASS restarts. If ``state.persist ``
1297
1299
is not called on a particular state variable before HASS stops, then that state variable will not be
1298
1300
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).
0 commit comments