-
Hello :) I am wondering if this is a limit off hass python, pyscript, or me being a newbe. With this simplifed exemple:
On my python, i get at the output
but using hass pyscript kernel i get the following error
Did i miss a limitation ? I am running the latest stable HASS from there docker repo in a development environment. Thank you ! EDIT: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
pyscript is Python, but there are some language limitations; features that are not available. In short, almost everything in pyscript (classes, functions, class methods, etc) are turned into classes internally. This makes, for one, using non-pyscript decorators difficult. The easiest way around this is to use the I have not tested this, but I believe this will work in your case: @pyscript_compile
def makeBaseMessage():
class BaseMessage:
@classmethod
def print_value(cls, value):
print(value)
return BaseMessage
BaseMessage = makeBaseMessage()
toto=BaseMessage()
toto.print_value("titi") |
Beta Was this translation helpful? Give feedback.
-
In this particular case, I believe it's subclassing that isn't working. As a whole, I'm really not sure. Subclassing, passing methods or classes created in pyscript to native python modules, and the use of non-pyscript decorators are issues I've run in to myself. But I don't know if a full list has been made. In short, the solution is, keep your pyscript code to very simple classes and methods. For everything else, use native python modules of |
Beta Was this translation helpful? Give feedback.
In this particular case, I believe it's subclassing that isn't working.
As a whole, I'm really not sure. Subclassing, passing methods or classes created in pyscript to native python modules, and the use of non-pyscript decorators are issues I've run in to myself. But I don't know if a full list has been made.
In short, the solution is, keep your pyscript code to very simple classes and methods. For everything else, use native python modules of
@pyscript_compile
. It just means you have to separate the logic between what talks to HASS and what doesn't, since anything in@pyscript_compile
won't be able to use pyscript functionality.