Closed cjlapao closed 2 months ago
@ALERTua Yes I did something similar yesterday,
class TestLight(Device):
def __init__(self, device_id: str, **args):
Device.init(self, device_id, **args)
if self.is_debug_enabled():
log.debug(f"Creating light {device_id} with {args}")
clean_args = self.clean_args(**args)
self.set_args(**clean_args)
self._attributes = LightAttributes(device_id)
self._tiggers = []
self.init(**args)
This is my approach, very similar
thanks
As you discovered, certain class features don't work properly in pyscript
. One specific challenge is that all functions in pyscript
are async, including class methods you create. That means that things like creating magic methods (eg, operator overloading) won't work, since python will expect those methods to be regular functions. One workaround is to create the class using regular python with @pyscript_compile
.
I would pin this issue for future generations and close it. Glad I helped.
I agree, I am satisfied with the solution I found and all works really well for me
I am trying to create some modules that contains code that is reusable and I am trying to use class inheritance to do so.
for example
this then creates an error as the super seems to not work properly
Is there any way I can bypass this?