From 0156e689ca74baf4c6184ff4e94a9a7e04ea6cd5 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Tue, 30 Jun 2026 19:27:04 +0200 Subject: [PATCH] config: wire TempSensor section from config.json to TempSensorSim PlantFactory.create() now accepts sensor_config dict; extracts type and kwargs, falls back to sigma=0.05/temp_offset=-0.15 defaults. brewpi.py passes config.get('TempSensor', {}). Templates updated with full TempSensor sections. Co-Authored-By: Claude Sonnet 4.6 --- components/plant/plant_factory.py | 13 ++++++++++--- config-real.json.tpl | 7 ++++++- config-sim.json.tpl | 8 +++++++- server/brewpi.py | 2 +- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/components/plant/plant_factory.py b/components/plant/plant_factory.py index 54e7287..9404a14 100644 --- a/components/plant/plant_factory.py +++ b/components/plant/plant_factory.py @@ -17,14 +17,21 @@ class PlantFactory: imported - only actually needed when plant_name picks the real rig.""" @staticmethod - def create(plant_name, dt, heater_config): + def create(plant_name, dt, heater_config, sensor_config=None): + sensor_config = sensor_config or {} if "sim" in plant_name: heater = HeaterFactory.create("sim", heater_config) pot = Pot(dt) - sensor = TempSensorFactory.create("sim", temp_offset=-0.15, sigma=0.05) + sensor_type = sensor_config.get('type', 'sim') + sensor_params = {k: v for k, v in sensor_config.items() if k != 'type'} + sensor_params.setdefault('temp_offset', -0.15) + sensor_params.setdefault('sigma', 0.05) + sensor = TempSensorFactory.create(sensor_type, **sensor_params) return heater, pot, sensor heater = HeaterFactory.create("Hendi", heater_config) pot = PotReal() - sensor = TempSensorFactory.create("max31865", temp_offset=-0.15) + sensor_params = {k: v for k, v in sensor_config.items() if k != 'type'} + sensor_params.setdefault('temp_offset', -0.15) + sensor = TempSensorFactory.create("max31865", **sensor_params) return heater, pot, sensor diff --git a/config-real.json.tpl b/config-real.json.tpl index da53ef5..f463cd8 100644 --- a/config-real.json.tpl +++ b/config-real.json.tpl @@ -1,7 +1,6 @@ { "ambient_temperature": 20, "Controller" : { - "stirrer_name": "pololu1376", "plant_name": "real", "pid_type": "Smith" }, @@ -35,11 +34,17 @@ } }, "Heater": { + "type": "hendi", "port": "/dev/ttyUSB0", "speed": "115200" }, "Stirrer": { + "type": "pololu1376", "port": "/dev/ttyACM0", "speed": "115200" + }, + "TempSensor": { + "type": "max31865", + "temp_offset": -0.15 } } diff --git a/config-sim.json.tpl b/config-sim.json.tpl index 95b636d..627d2c1 100644 --- a/config-sim.json.tpl +++ b/config-sim.json.tpl @@ -1,7 +1,6 @@ { "ambient_temperature": 20, "Controller" : { - "stirrer_name": "sim", "plant_name": "sim", "pid_type": "Smith" }, @@ -41,5 +40,12 @@ "Stirrer": { "port": "/dev/ttyACM0", "speed": "115200" + }, + "TempSensor": { + "type": "sim", + "temp_offset": 0.0, + "sigma": 0.05, + "stirrer_sigma": 0.0, + "stirrer_tau": 20.0 } } diff --git a/server/brewpi.py b/server/brewpi.py index 2286449..32a0e18 100755 --- a/server/brewpi.py +++ b/server/brewpi.py @@ -90,7 +90,7 @@ if __name__ == '__main__': # (the modeled plant)/TempSensorSim; anything else gets HeaterHendi/ # PotReal (no model - the real kettle does its own physics)/ # TempSensor_max31865. - heater, pot, sensor = PlantFactory.create(config['Controller']['plant_name'], DT, config['Heater']) + heater, pot, sensor = PlantFactory.create(config['Controller']['plant_name'], DT, config['Heater'], config.get('TempSensor', {})) sensor_task = TempSensorTask(sensor, DT_TASK, dispatcher.msgio_get("Sensor")) taskmgr.add(sensor_task)