pymysensors icon indicating copy to clipboard operation
pymysensors copied to clipboard

Unable to use "timeout" argument in gateway instantiation

Open kristianwiklund opened this issue 5 years ago • 3 comments

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()

kristianwiklund avatar Jul 05 '20 05:07 kristianwiklund

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

MartinHjelmare avatar Jul 05 '20 08:07 MartinHjelmare

The same issue applies to use of 'reconnect_timeout' parameter and serial gateway as well.

softerra avatar Jan 18 '22 16:01 softerra

I noticed this too.

createcandle avatar Jan 24 '22 17:01 createcandle