mattsaxon / pysonofflan

Python interface for controlling Sonoff smart switches/plugs running original Itead firmware, locally, in "LAN mode".
MIT License
32 stars 23 forks source link

AttributeError: 'ServiceInfo' object has no attribute 'address' #253

Open tomk235 opened 3 years ago

tomk235 commented 3 years ago

Description

pysonofflanr3 --host [my_sonoff_ip] -l DEBUG --api_key [mytotallysecretkey] --device_id [and_its_device_id] state or pysonofflanr3 discover

bring up the error:

root@[machine]:/usr/src/app# pysonofflanr3 discover 2021-02-16 19:30:17,651 - info: Attempting to discover Sonoff LAN Mode devices on the local network, please wait... Exception in thread zeroconf-ServiceBrowserewelink._tcp.local._82: Traceback (most recent call last): File "/usr/local/lib/python3.9/threading.py", line 954, in _bootstrap_inner self.run() File "/usr/local/lib/python3.9/site-packages/zeroconf/init__.py", line 1755, in run self._service_state_changed.fire( File "/usr/local/lib/python3.9/site-packages/zeroconf/init.py", line 1513, in fire h(*kwargs) File "/usr/local/lib/python3.9/site-packages/zeroconf/init.py", line 1611, in on_change listener.add_service(args) File "/usr/local/lib/python3.9/site-packages/pysonofflanr3/discover.py", line 40, in add_service ip = utils.parseAddress(info.address) + ":" + str(info.port) AttributeError: 'ServiceInfo' object has no attribute 'address'


or the error:

root@[machine]:/usr/src/app# pysonofflanr3 --host [my_sonoff_ip] -l DEBUG --api_key [the_secret_key] --device_id [the_id] state 2021-02-16 19:27:02,510 - info: Initialising SonoffSwitch with host 172.23.8.158 2021-02-16 19:27:02,510 - debug: Initializing SonoffLANModeClient class in SonoffDevice 2021-02-16 19:27:02,511 - debug: enter send_availability_loop() 2021-02-16 19:27:02,512 - debug: waiting for connection 2021-02-16 19:27:02,512 - debug: send_updated_params_loop is active on the event loop 2021-02-16 19:27:02,512 - debug: Starting loop waiting for device params to change 2021-02-16 19:27:02,512 - debug: send_updated_params_loop now awaiting event 2021-02-16 19:27:02,632 - info: Service type _ewelink.tcp.local. of name eWeLink[some_id]._ewelink._tcp.local. added Exception in thread zeroconf-ServiceBrowserewelink._tcp.local._31: Traceback (most recent call last): File "/usr/local/lib/python3.9/threading.py", line 954, in _bootstrap_inner self.run() File "/usr/local/lib/python3.9/site-packages/zeroconf/init__.py", line 1755, in run self._service_state_changed.fire( File "/usr/local/lib/python3.9/site-packages/zeroconf/init.py", line 1513, in fire h(*kwargs) File "/usr/local/lib/python3.9/site-packages/zeroconf/init.py", line 1611, in on_change listener.add_service(args) File "/usr/local/lib/python3.9/site-packages/pysonofflanr3/client.py", line 154, in add_service self.update_service(zeroconf, type, name) File "/usr/local/lib/python3.9/site-packages/pysonofflanr3/client.py", line 166, in update_service found_ip = utils.parseAddress(info.address) AttributeError: 'ServiceInfo' object has no attribute 'address'


What I Did

pysonofflanr3 discover pysonofflanr3 --host [my_sonoff_ip] -l DEBUG --api_key [the_secret_key] --device_id [the_id] state

Solution

change "found_ip = utils.parseAddress(info.address)" to found_ip = utils.parseAddress(info.addresses[0]) in those files: joe /usr/local/lib/python3.9/site-packages/pysonofflanr3/discover.py line 40 joe /usr/local/lib/python3.9/site-packages/pysonofflanr3/client.py line 119 & line 166

as zeroconf has changed its api from deprecated address to addresses

gulp79 commented 3 years ago

Thank you, i've had the same problem, resolved with yours changes.

camelcamro commented 3 years ago

pls can someone tell this to master of "pysonofflanr3"

as there are other users which can'T see that in the WIKI ... and that is a showstopper when someone is using the newest sources ...

thx

Teiby commented 11 months ago

Thanks for the solution. Guess this will never ever be fixed.

dauheeIRL commented 11 months ago

I have used the library to build https://github.com/dauheeIRL/SonoffSimpleLAN which currently works