refactor: replace plant_name with per-component type keys in config
PlantFactory.create() no longer takes plant_name; sim vs real is derived from Heater.type. StirrerFactory is wired from Stirrer.type. HeaterFactory registry key lowercased to "hendi" to match config. Controller.plant_name removed from both config templates. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -5,33 +5,29 @@ from components.plant.pot_real import PotReal
|
||||
|
||||
|
||||
class PlantFactory:
|
||||
"""Builds the heater/pot/sensor trio together, as one consistent rig,
|
||||
rather than each picked independently via its own *_name config key -
|
||||
sim and real hardware are never actually mixed and matched in
|
||||
practice, so Controller.plant_name alone now decides all three (see
|
||||
server/brewpi.py).
|
||||
"""Builds the heater/pot/sensor trio together as one consistent rig.
|
||||
|
||||
Delegates the actual construction to HeaterFactory/TempSensorFactory
|
||||
rather than importing HeaterHendi/TempSensor_max31865 directly, so
|
||||
those classes' hardware-only deps (spidev, pyserial) stay lazily
|
||||
imported - only actually needed when plant_name picks the real rig."""
|
||||
Each component's type comes from its own config section (Heater.type,
|
||||
TempSensor.type) rather than a single plant_name key. The heater type
|
||||
determines sim vs real: sim gets Pot (modelled plant) and TempSensorSim;
|
||||
anything else gets PotReal and whatever TempSensor.type names.
|
||||
|
||||
Delegates to HeaterFactory/TempSensorFactory so hardware-only deps
|
||||
(spidev, pyserial) stay lazily imported."""
|
||||
|
||||
@staticmethod
|
||||
def create(plant_name, dt, heater_config, sensor_config=None):
|
||||
def create(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_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_type = heater_config.get('type', 'sim')
|
||||
plant_sim = (heater_type == 'sim')
|
||||
|
||||
heater = HeaterFactory.create("Hendi", heater_config)
|
||||
pot = PotReal()
|
||||
heater = HeaterFactory.create(heater_type, heater_config)
|
||||
pot = Pot(dt) if plant_sim else PotReal()
|
||||
|
||||
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 = TempSensorFactory.create("max31865", **sensor_params)
|
||||
if plant_sim:
|
||||
sensor_params.setdefault('sigma', 0.05)
|
||||
sensor = TempSensorFactory.create(sensor_type, **sensor_params)
|
||||
return heater, pot, sensor
|
||||
|
||||
Reference in New Issue
Block a user