Replies: 1 comment
-
|
Just to add my 2 cents because I've tripped over this recently so I can confirm this still happens. The issue as far as I can tell is with how destructors work....or rather don't work. In a basic class you can add @pyscript_compile decorators to the destructor (and explicitly call My suggestion is to avoid calling the constructor in the global scope of the module. This is because it will be called when the module is loaded which can lead to issues depending on load order wrt entites. Instead, construct the objects in a startup function. Then similarly have a For some or other reason, the derrived dtor will never call into a base class function....or at least I couldn't get it to work without |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
So I tried to be clever and structure my code into classes. It works, kind of.
My use case is I have a few ZigBee devices of the same type in different rooms for which I wait for events and then do stuff.
I created a base class for the zha event, then classes for different devices that inherit from the base class, and then I created instanses of the classes in several script files (pyscript/scripts/).
The base class creates a list of triggers that is attached to
self, so I expected those triggers to be destroyed when the reference to the class instance is lost, ie when reloading the script that creates the class instance and has the reference to it.But that is not happening, instead every time I reload the script it just adds more triggers without destroying the previous ones. I have to reload the file that contains the definition of the base class for the triggers to be destroyed.
But if I don't have a reference to the instance (remove
ws_hallwaybelow) then nothing happens when I push the switch which I assume is because the triggers have been destroyed when the instance was not referenced anymore.What am I missing here?
This is basically how I implemented it:
pyscript/modules/zha.py:
pyscript/modules/philips_hue.py:
pyscript/scripts/hallway.py:
Beta Was this translation helpful? Give feedback.
All reactions