Refactor TemperatureSensor: comment out debug print statement and remove example usage code
This commit is contained in:
parent
f07fcd6af1
commit
c788dcc8f5
@ -16,7 +16,7 @@ class TemperatureSensor:
|
|||||||
try:
|
try:
|
||||||
# Convert bytearray to bytes so they can be used as dict keys
|
# Convert bytearray to bytes so they can be used as dict keys
|
||||||
self.roms = [bytes(rom) for rom in self.ds_sensor.scan()]
|
self.roms = [bytes(rom) for rom in self.ds_sensor.scan()]
|
||||||
print(f'Found {len(self.roms)} DS18X20 sensor(s)')
|
# print(f'Found {len(self.roms)} DS18X20 sensor(s)')
|
||||||
return self.roms
|
return self.roms
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f'Error scanning sensors: {e}')
|
print(f'Error scanning sensors: {e}')
|
||||||
@ -61,15 +61,4 @@ class TemperatureSensor:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f'Error reading temperatures: {e}')
|
print(f'Error reading temperatures: {e}')
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
# Example usage / test code
|
|
||||||
if __name__ == "__main__":
|
|
||||||
sensor = TemperatureSensor(pin=10)
|
|
||||||
|
|
||||||
while True:
|
|
||||||
temps = sensor.read_all_temps(unit='F')
|
|
||||||
for rom, temp in temps.items():
|
|
||||||
print(f'Sensor {rom.hex()}: {temp:.2f}°F')
|
|
||||||
print()
|
|
||||||
time.sleep(5)
|
|
||||||
Loading…
x
Reference in New Issue
Block a user