kbr / fritzconnection

Python-Tool to communicate with the AVM Fritz!Box by the TR-064 protocol and the AHA-HTTP-Interface
MIT License
303 stars 59 forks source link

Error when asking for list of home automation devices #138

Closed scientific-method-course closed 2 years ago

scientific-method-course commented 2 years ago

When asking for a list of home automation devices the homeauto script chokes:

myprompt$ fritzhomeauto -p XXXXXX

fritzconnection v1.9.0
FRITZ!Box 7590 at http://169.254.1.1
FRITZ!OS: 7.29

FritzHomeautomation:
Status of registered home-automation devices:

Device Name             AIN                 Power[W]   t[°C]   switch
Traceback (most recent call last):
  File "/usr/local/bin/fritzhomeauto", line 10, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.7/dist-packages/fritzconnection/cli/fritzhomeauto.py", line 80, in main
    report_status(fh, arguments)
  File "/usr/local/lib/python3.7/dist-packages/fritzconnection/cli/fritzhomeauto.py", line 51, in report_status
    report_compact(fh)
  File "/usr/local/lib/python3.7/dist-packages/fritzconnection/cli/fritzhomeauto.py", line 34, in report_compact
    for di in fh.device_information():
  File "/usr/local/lib/python3.7/dist-packages/fritzconnection/lib/fritzhomeauto.py", line 78, in device_information
    info.append(info)
AttributeError: 'dict' object has no attribute 'append'

Looking at what happens at in device_information, I think the error is in the re-use of the variable info. This can easily be solved in the following way (where I included the line numbers to that you can compare what I changed in fritzhomeauto.py:

     68     def device_information(self):
     69         """
     70         Returns a list of dictionaries for all known homeauto-devices.
     71         """
     72         info = list()
     73         for n in itertools.count():
     74             try:
     75                 newinfo = self.get_device_information_by_index(n) # Store the info in a temporary variable
     76                 info.append(newinfo) # Append the temporary variable to info, provided the try was O
     77             except IndexError:
     78                 break
     79         return info  # Return info whatever happened, it will be at least an empty list, perhaps more

Hope this helps (and many thanks for the useful library). Best, Arnold

(PS: I now see that the name showsn for my account is related to the course material for which I used my github account until know; I had no intention to hide in anyway).

kbr commented 2 years ago

Indeed, this bug seems to be introduced with 1.9.0 where some typos have been fixed without taking care that in this special case an existing label gets overwritten. Thanks for reporting.

kbr commented 2 years ago

Fixed in 1.9.1