Airthings / waveplus-reader

MIT License
133 stars 61 forks source link

TypeError: fromhex() argument 1 must be string or read-only buffer, not None #16

Open siglun88 opened 4 years ago

siglun88 commented 4 years ago

Got the following error when trying to read the device:

Traceback (most recent call last):
  File "read_waveplus.py", line 222, in <module>
    waveplus.connect()
  File "read_waveplus.py", line 124, in connect
    SN = parseSerialNumber(ManuData)
  File "read_waveplus.py", line 87, in parseSerialNumber
    ManuData = bytearray.fromhex(ManuDataHexStr)
TypeError: fromhex() argument 1 must be string or read-only buffer, not None

In the connect method defined on line 113 it turns out that dev.getValueText(255) returns None at some point in the for loop.

Quick Fix:

Rewrite the for-loop with an if-statement to check if the value of ManuData is None. And if that is the case, continue the for-loop without calling parseSerialNumber.

On line 121, change the for-loop to this:

for dev in devices:
                    ManuData = dev.getValueText(255)
                    if (ManuData is None):
                        continue
                    SN = parseSerialNumber(ManuData)
                    if (SN == self.SN):
                        self.MacAddr = dev.addr  # exits the while loop on next conditional check
                        break  # exit for loop