kbr / fritzconnection

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

Math domain error in fritztools.py #87

Closed sven-geisenhainer closed 3 years ago

sven-geisenhainer commented 3 years ago

When running the following sample Python code from the documentation with my FB7560:

fc = FritzStatus(address='192.168.178.1', password='****')
while True:
    print(fc.str_transmission_rate)
    time.sleep(2)

After a few lines of transmission rates printed, the programm crashes:

Traceback (most recent call last):
  File "/app/App.py", line 17, in <module>
    print(fc.str_transmission_rate)
  File "/usr/local/lib/python3.10/site-packages/fritzconnection/lib/fritzstatus.py", line 142, in str_transmission_rate
    return (format_num(upstream), format_num(downstream))
  File "/usr/local/lib/python3.10/site-packages/fritzconnection/lib/fritztools.py", line 30, in format_num
    num, dim = byte_formatter(num)
  File "/usr/local/lib/python3.10/site-packages/fritzconnection/lib/fritztools.py", line 16, in byte_formatter
    log = min(int(math.log10(value) / 3), len(dim))

Does not always happen, crash is not reproducible, but it will always happen sooner or later. Seems a numeric value is invalid (NaN, division by zero, etc).

kbr commented 3 years ago

Yes, the logarithm of zero is undefined. That's indeed a bug not covered by the tests. Thank you for reporting.

kbr commented 3 years ago

fixed with version 1.4.2