heater_name/sensor_name/plant_name were three independent config keys, each picked via its own factory - in practice sim and real hardware are never actually mixed and matched, so this could (nonsensically) disagree, e.g. a real heater paired with a simulated sensor. Add PlantFactory (components/plant/plant_factory.py): plant_name alone now builds the whole rig together. "sim" gets HeaterSim/Pot (the modeled plant, as before)/TempSensorSim. Anything else gets HeaterHendi/PotReal/TempSensor_max31865 - PotReal is a new, deliberately unmodeled Pot for the real, physical kettle (components/plant/pot_real.py): the real temperature comes straight from the real sensor, not from a model, so it just accepts and ignores set_plant_params()/ set_ambient_temperature()/initial() and reports no temperature of its own, satisfying PotTask/SudTask's interface with nothing to actually simulate. heater_name/sensor_name are gone from config.json.templ; server/brewpi.py delegates to HeaterFactory/TempSensorFactory lazily from inside PlantFactory, same as before, so real hardware's spidev/pyserial deps still aren't needed just to import the module.
31 lines
1.2 KiB
Python
31 lines
1.2 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,
|
|
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).
|
|
|
|
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."""
|
|
|
|
@staticmethod
|
|
def create(plant_name, dt, heater_config):
|
|
if "sim" in plant_name:
|
|
heater = HeaterFactory.create("sim", heater_config)
|
|
pot = Pot(dt)
|
|
sensor = TempSensorFactory.create("sim", temp_offset=-0.15, variance=0.01)
|
|
return heater, pot, sensor
|
|
|
|
heater = HeaterFactory.create("Hendi", heater_config)
|
|
pot = PotReal()
|
|
sensor = TempSensorFactory.create("max31865", temp_offset=-0.15)
|
|
return heater, pot, sensor
|