@@ -1092,13 +1092,13 @@ level will not appear in the log. Each log message function uses a log name of t
1092
1092
1093
1093
.. code :: yaml
1094
1094
1095
- custom_components.pyscript.file.FILENAME .FUNCNAME
1095
+ custom_components.pyscript.file.SCRIPTNAME .FUNCNAME
1096
1096
1097
1097
where ``FUNCNAME `` is the name of the top-level Python function (e.g., the one called by a trigger
1098
- or service), defined in the script file ``FILENAME .py ``. See the `Global Context <#global-context >`__
1098
+ or service), defined in the script file ``SCRIPTNAME .py ``. See the `Global Context <#global-context >`__
1099
1099
section for the logging paths for other cases.
1100
1100
1101
- That allows you to set the log level for each Python top-level function separately if necessary.
1101
+ That allows you to set the log level for each Python top-level script or function separately if necessary.
1102
1102
That setting also applies to any other Python functions that the top-level Python function calls.
1103
1103
For example, these settings:
1104
1104
@@ -1108,15 +1108,35 @@ For example, these settings:
1108
1108
default : info
1109
1109
logs :
1110
1110
custom_components.pyscript.file : info
1111
- custom_components.pyscript.file.my_scripts .my_function : debug
1111
+ custom_components.pyscript.file.my_script .my_function : debug
1112
1112
1113
1113
will log all messages at ``info `` or higher (ie: ``log.info() ``, ``log.warning() `` and
1114
- ``log.error() ``), and inside ``my_function `` defined in the script file ``my_scripts .py `` (and any
1114
+ ``log.error() ``), and inside ``my_function `` defined in the script file ``my_script .py `` (and any
1115
1115
other functions it calls) will log all messages at ``debug `` or higher.
1116
1116
1117
1117
Note that in Jupyter, all the ``log `` functions will display output in your session, independent of
1118
1118
the ``logger `` configuration settings.
1119
1119
1120
+ Changing the log level via the main configuration yaml file will typically require a restart of HASS.
1121
+ To avoid that, you can set the log level for any specific logging path by calling the ``logger.set_level ``
1122
+ service from Jupyter, VSC, or in a ``pyscript `` script; for example:
1123
+
1124
+ .. code :: python
1125
+
1126
+ logger.set_level(** {" custom_components.pyscript.file.my_script" : " debug" })
1127
+
1128
+ will change the log level for the ``my_script.py `` script to ``debug ``, while:
1129
+
1130
+ .. code :: python
1131
+
1132
+ logger.set_level(** {" custom_components.pyscript.file.my_script.func1" : " debug" })
1133
+
1134
+ will change the log level for the ``func1() `` function in ``my_script.py `` script to ``debug ``.
1135
+ You can change multiple components in a single call just by adding them to the ``**kwargs `` dict.
1136
+
1137
+ Alternatively, you can use the `Developer Tools <https://www.home-assistant.io/docs/tools/dev-tools/ >`__
1138
+ to call the ``logger.set_level `` service with the logging path and desired level as parameters.
1139
+
1120
1140
Tasks
1121
1141
^^^^^
1122
1142
@@ -1409,12 +1429,21 @@ global context, to the granularity of specific functions eg:
1409
1429
default : info
1410
1430
logs :
1411
1431
custom_components.pyscript.file : info
1412
- custom_components.pyscript.file.my_scripts .my_function : debug
1432
+ custom_components.pyscript.file.my_script .my_function : debug
1413
1433
custom_components.pyscript.apps.my_app : debug
1414
1434
custom_components.pyscript.apps.my_app.my_function : debug
1415
1435
1416
1436
Each Jupyter global context name is ``jupyter_NNN `` where ``NNN `` is a unique integer starting at 0.
1417
1437
1438
+ You can set the log level for one or more logging paths by calling the ``logger.set_level `` service
1439
+ from Jupyter, VSC, or in a ``pyscript `` script; for example:
1440
+
1441
+ .. code :: python
1442
+
1443
+ logger.set_level(** {" custom_components.pyscript.file.my_script" : " debug" })
1444
+
1445
+ will change the log level for the ``my_script.py `` script to ``debug ``.
1446
+
1418
1447
When a script file has changed (or an app's configuration has changed, provided the ``yaml `` file is
1419
1448
below the ``pyscript `` directory), a reload is triggered, and the corresponding global context whose
1420
1449
names starts with ``file. ``, ``modules. ``, ``apps. `` or ``scripts. `` is removed. As each file is
@@ -1980,6 +2009,14 @@ Here are some areas where pyscript differs from real Python:
1980
2009
be declared ``async ``. Unless the Python module is designed to support async callbacks, it is not
1981
2010
currently possible to have Python modules and packages call pyscript functions. The workaround is
1982
2011
to move your callbacks from pyscript and make them native Python functions; see `Importing <#importing >`__.
2012
+ - Continuing that point, special methods (eg, `__eq__ `) in a class created in `pyscript ` will not work since
2013
+ they are async functions and Python will not be able to call them. The two workarounds are to
2014
+ use the ``@pyscript_compile `` decorator so the method is compiled to a native (non-ascync) Python
2015
+ function, or write your class in native Python and import it into ``pyscript ``; see `Importing <#importing >`__.
2016
+ - The ``import `` function in ``pyscript `` fails to import certain complex packages. This is an open bug and
2017
+ it would be great if someone with some Python expertise could help fix it. In the meantime, the workaround
2018
+ is to import the module in a native Python file, and then import that shim module into pyscript.
2019
+ See `Importing <#importing >`__.
1983
2020
- pyscript and the HASS primitives that it uses are not thread safe - the code should only be executed
1984
2021
in the main event loop. The ``task.executor() `` function is one way that regular Python code
1985
2022
(not pyscript code) can safely be executed in a separate thread. The ``threading `` package can
0 commit comments