Skip to content

Commit

Permalink
Added exception handling around attempting to load the w1therm sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
fall-byrd committed Sep 21, 2024
1 parent 25f989a commit 187e575
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions backend/hardware/thermometer/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,27 @@
and either the individual files or backend/config.py for configuration information.
"""

from hardware.thermometer.w1_therm import W1TempSensor
from hardware.thermometer.serial import SerialTempSensor
from hardware.thermometer.serial_simulation import SerialTempSensorSimulation

W1_IMPORT_ERROR = False

try:
from w1thermsensor import W1ThermSensor
except Exception:
# We have to catch broadly for this exception as there is an error defined
# in the w1thermsensor library to attempt to catch this issue
# however the exception is triggered on any module import as
# the load is attempted in the __init__ file in the base of the repo
# so no imports will work at all if there is a load error
W1_IMPORT_ERROR = True
else:
from hardware.thermometer.w1_therm import W1TempSensor


def createThermometer(thermometerConfig: dict, devices: dict):
thermometerType = thermometerConfig['implementation']
if thermometerType == "w1_therm":
if thermometerType == "w1_therm" and not W1_IMPORT_ERROR:
return W1TempSensor()
elif thermometerType == "serial":
return SerialTempSensor(thermometerConfig)
Expand Down

0 comments on commit 187e575

Please sign in to comment.