pymysensors
pymysensors copied to clipboard
Unable to use "timeout" argument in gateway instantiation
Version:
pymysensors 0.20.1, installed by pip3
Environment:
Ubuntu 18.04.4 LTS, x86_64, python 3.6.9
Expected behavior
Instantiation of a tcp gateway object with altered timeouts. (If my testing of different versions isn't completely off, this worked in 0.18.0, but not from 0.19.0 and onwards.)
Actual behavior
TypeError: init() got an unexpected keyword argument 'timeout'
python3 mystest.py
Traceback (most recent call last):
File "mystest.py", line 10, in <module>
persistence_file='mysensors.pickle', protocol_version='1.4')
File "/usr/local/lib/python3.6/dist-packages/mysensors/gateway_tcp.py", line 76, in __init__
super().__init__(transport, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/mysensors/__init__.py", line 197, in __init__
super().__init__(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/mysensors/gateway_tcp.py", line 23, in __init__
super().__init__(**kwargs)
TypeError: __init__() got an unexpected keyword argument 'timeout'
How to recreate:
Use code in README to instantiate a tcp gateway with a timeout as below
import mysensors.mysensors as mysensors
def event(message):
"""Callback for mysensors updates."""
print("sensor_update " + str(message.node_id))
GATEWAY = mysensors.TCPGateway(
'10.168.0.2', port=5003, timeout=1.0, reconnect_timeout=10.0,
event_callback=event, persistence=True,
persistence_file='mysensors.pickle', protocol_version='1.4')
GATEWAY.start()
Thanks for the report! I see the problem. We need to pop the timeout parameters from kwargs before passing kwargs on to the parent gateway.
https://github.com/theolind/pymysensors/blob/56c08d52f706e26229b8472547afcb31945258fb/mysensors/gateway_tcp.py#L75-L76
The same issue applies to use of 'reconnect_timeout' parameter and serial gateway as well.
I noticed this too.