Files
jensandClaude Sonnet 4.6 0495e177c4 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>
2026-06-30 19:31:39 +02:00

34 lines
1.3 KiB
Python

from components.actor import HeaterFactory
from components.sensor import TempSensorFactory
from components.plant.pot import Pot
from components.plant.pot_real import PotReal
class PlantFactory:
"""Builds the heater/pot/sensor trio together as one consistent 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(dt, heater_config, sensor_config=None):
sensor_config = sensor_config or {}
heater_type = heater_config.get('type', 'sim')
plant_sim = (heater_type == 'sim')
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)
if plant_sim:
sensor_params.setdefault('sigma', 0.05)
sensor = TempSensorFactory.create(sensor_type, **sensor_params)
return heater, pot, sensor