mirror of
https://github.com/NotAShelf/air-quality-monitor.git
synced 2024-11-22 13:20:48 +00:00
handle serial port unavailable
This commit is contained in:
parent
a22882a169
commit
5c7691ba6b
1 changed files with 6 additions and 1 deletions
|
@ -17,7 +17,12 @@ class AirQualityMonitor:
|
|||
SERIAL_DEVICE = os.environ.get("SERIAL_DEVICE", "/dev/ttyUSB0")
|
||||
|
||||
def __init__(self):
|
||||
self.ser = serial.Serial(self.SERIAL_DEVICE)
|
||||
# if path does not exist, error and exit
|
||||
if not os.path.exists(self.SERIAL_DEVICE):
|
||||
raise RuntimeError(f"Serial device {self.SERIAL_DEVICE} not found.")
|
||||
else:
|
||||
print(f"Serial device {self.SERIAL_DEVICE} found.")
|
||||
self.ser = serial.Serial(self.SERIAL_DEVICE)
|
||||
|
||||
def get_measurement(self):
|
||||
"""Fetches a measurement from the sensor and returns it."""
|
||||
|
|
Loading…
Reference in a new issue