timofurrer / w1thermsensor

A Python package and CLI tool to work with w1 temperature sensors like DS1822, DS18S20 & DS18B20 on the Raspberry Pi, Beagle Bone and other devices.
MIT License
493 stars 113 forks source link

Received IndexError instead of SensorNotReadyError from get_raw_sensor_strings() when reading DS18B20 #96

Closed DietBru closed 3 years ago

DietBru commented 3 years ago

I am having a few DS18B20 sensors connected to raspberry pi zero. From time to time the contents of the file /sys/bus/w1/devices/28.../w1_slave appears to be empty (not sure why). Hence the contents of the list data in the method get_raw_sensor_strings() in file async_core.py is empty as well. Accessing it raises an IndexError.

Changing line 65 in file async_core.py from:

     if (
            data[0].strip()[-3:] != "YES" or "00 00 00 00 00 00 00 00 00" in data[0]
        ):  # pragma: no cover
            raise SensorNotReadyError(self) 

to

     if (
           not data or data[0].strip()[-3:] != "YES" or "00 00 00 00 00 00 00 00 00" in data[0]
        ):  # pragma: no cover
            raise SensorNotReadyError(self) 

resolves the problem.

Thanks.

PS: I am using version w1thermsensor 2.0.0a1

timofurrer commented 3 years ago

Thanks for the report. We've already fixed that for the non-async version of the code, see #94 .

I've made the same change now in the async code and will release asap.

timofurrer commented 3 years ago

I've released v2.0.0a2

flyte commented 3 years ago

Hey, any chance this bugfix could be backported to the 1.3.x version? Some of our Python 2 using users at https://github.com/flyte/pi-mqtt-gpio are hitting this issue.

bsimmo commented 3 years ago

Or they could fork it and make a python2 port.

or get with the game and update to python3 ;-)

(yeah, not much help that, sorry :-) )

On Sun, 24 Jan 2021 at 17:59, Ellis Percival notifications@github.com wrote:

Hey, any chance this bugfix could be backported to the 1.3.x version? Some of our Python 2 using users at flyte/pi-mqtt-gpio are hitting this issue.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/timofurrer/w1thermsensor/issues/96#issuecomment-766403352, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACYAXN7ZUG5WVZPGQX2RYNDS3RNXLANCNFSM4QPSFTBQ .

flyte commented 3 years ago

Just hoped it'd be a trivial fix.

We're only supporting Python 2 until it becomes too much of a pain in the butt, or I finally release the Python 3 only asyncio version.

timofurrer commented 3 years ago

To be honest, the fix would be trivial - however, the very last Python 2 release for w1thermsensor already happened and since it's long been deprecated any ways I don't want to support it any longer.

If you really need Python 2 I suggest that you go with @bsimmo solution of a fork-and-port.

In any case, I highly recommend you to drop Python 2 support too and go with a supported Python 3 version - but I suspect you are aware of that already :)

🍻