pyduofern
pyduofern copied to clipboard
TypeError: object.__init__() takes no parameters
Hi,
first of all, thanks for this great implementation! I got everything working on the command line, and I am now trying to get access directly from python working.
Executing your example
from pyduofern.duofern_stick import DuofernStick
import time
stick = DuofernStick(device="/dev/duofernstick") # by default looks for /dev/duofernstick
stick_initialize() # do some initialization sequence with the stick
stick.start() # start the stick in a thread so it keeps communicating with your blinds
time.sleep(10) # let it settle to be able to talk to your blinds.
# your code here
# this uses internal variables of the duofern parser module and likely I will wrap it in
# the future.
print(stick.duofern_parser.modules['by_code']['1ff1d3']['position'])
.. throws error:
Traceback (most recent call last):
File "rollo_test.py", line 4, in <module>
stick = DuofernStick(device="/dev/duofernstick") # by default looks for /dev/duofernstick
File "/usr/local/lib/python3.5/dist-packages/pyduofern/duofern_stick.py", line 85, in __init__
super().__init__(*args, **kwargs)
TypeError: object.__init__() takes no parameters
/dev/duofernstick is available on my system.
Removing the "device="/dev/duofernstick" part from stick object creation code, leaving "stick = DuofernStick()", throws error:
Traceback (most recent call last):
File "rollo_test.py", line 5, in <module>
stick = DuofernStick() # by default looks for /dev/duofernstick
File "/usr/local/lib/python3.5/dist-packages/pyduofern/duofern_stick.py", line 92, in __init__
duofern_parser = Duofern(send_hook=self.add_serial_and_send, changes_callback=changes_callback)
AttributeError: 'DuofernStick' object has no attribute 'add_serial_and_send'
Any idea what I am doing wrong?
It works fine using the "DuofernStickThreaded" class, which the CLI script also uses.
stick = DuofernStickThreaded(serial_port="/dev/duofernstick")
stick._initialize()
stick.start()
The error results from the the super().init call in DuofernStick() which results in a call of object.init. The init(*args, **kwargs) function of an object only checks that no(!) parameters were given. Calling DuofernStick(device="...") provides a paramter and that causes the error.
Therfore another solution would be to remove the call of super().init(*args, **kwargs) from DuofernStick().
The code example was fixed in the readme, therefore I'll close this issue.
But one remark in case someone reads this in the future: DuofernStick
shouldn't be used directly any more, but either DuofernStickThreaded
or DuofernStickAsync
depending on whether one wants to use the asynchronous or thread-based api. When in doubt chose DuofernStickThreaded
.
I believe the readme lines containing DuofernStick
still come from the time when there was only a threaded version of the stick.