That code is not very well written. There's code duplication all over the place, especially in the original.
It should not need a separate function for each sensor. One common read_temp() function which could be passed the serial number of the sensor would work. Then you could build a list of sensors at the beginning and repeated call read_temp with the sensor names. Then you don't need to change the code at all if you make any changes to the sensors.
I'm not a Python programmer, but I reckon I could get something working to do that in less than 20 minutes.
Also, rather than having read_temp[n]() return two values when you only need one, you could change it to only return the one you want in the format you want. Then you don't have to extract it afterwards.
It should not need a separate function for each sensor. One common read_temp() function which could be passed the serial number of the sensor would work. Then you could build a list of sensors at the beginning and repeated call read_temp with the sensor names. Then you don't need to change the code at all if you make any changes to the sensors.
I'm not a Python programmer, but I reckon I could get something working to do that in less than 20 minutes.
Also, rather than having read_temp[n]() return two values when you only need one, you could change it to only return the one you want in the format you want. Then you don't have to extract it afterwards.
Statistics: Posted by rpdom — Sat Dec 23, 2023 7:32 am