Anrijs / Aranet4-Python

Aranet4, Aranet2 and Aranet Radiation Python client
MIT License
212 stars 18 forks source link

Exception when running with Aranet2 with a passive scanner that doesn't provide device name #40

Closed thecode closed 5 months ago

thecode commented 5 months ago

https://github.com/Anrijs/Aranet4-Python/blob/7ba172406b2ba6f523cf6ed7c29a1c2d1f3d993c/aranet4/client.py#L377-L378 breaks Aranet2 device without name

  File "/home/vscode/.local/lib/python3.12/site-packages/aranet4/client.py", line 377, in __init__
    if (not device.name and len(raw_bytes) in [7,22]) or "Aranet4" in device.name:
                                                         ^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: argument of type 'NoneType' is not iterable

Maybe change this to something like:

if device.name and "Aranet4" in device.name or len(raw_bytes) in [7,22]:
    raw_bytes.insert(0,0) 
Anrijs commented 5 months ago

Should be fixed in 2.3.3. Also added some tests to avoid this in future.