Refactor temperature_sensor.py: add SENSOR_CONFIG for sensor initialization and improve get_configured_sensors function

This commit is contained in:
Aaron 2025-11-04 19:58:56 -05:00
parent 473467e73f
commit 07d04a6084

View File

@ -62,4 +62,27 @@ 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
# Sensor configuration registry
SENSOR_CONFIG = {
'inside': {
'pin': 10,
'label': 'Inside',
'alert_high': 80.0,
'alert_low': 70.0
},
'outside': {
'pin': 11,
'label': 'Outside',
'alert_high': 85.0,
'alert_low': 68.0
}
}
def get_configured_sensors():
"""Return dictionary of configured sensor instances."""
sensors = {}
for key, config in SENSOR_CONFIG.items():
sensors[key] = TemperatureSensor(pin=config['pin'], label=config['label'])
return sensors