from pathlib import Path from tempfile import TemporaryDirectory from app.auto.config import ( load_auto_config_components, ) from app.auto.temperature_policy import ( TemperaturePolicy, ) from app.auto.elica_assist import ( ElicaAutoAssistState, ) BROKEN_CO2_CONFIG = """ version: 1 check_interval: 5.0 co2: base_speed: 2 hysteresis: 100 thresholds: - ppm: 700 speed: 2 - ppm: 1000 speed: 3 temperature: hysteresis: 0.5 elica_assist: enabled: false speed_map: 4: 1 5: 2 6: 3 """ def main(): with TemporaryDirectory() as directory: path = ( Path(directory) / "auto.yaml" ) path.write_text( BROKEN_CO2_CONFIG, encoding="utf-8", ) config = ( load_auto_config_components( path ) ) # ---------------------------------------------- # CO2 должен быть отключён. # ---------------------------------------------- assert config.co2 is None assert "co2" in config.errors assert ( "First threshold speed must be " "greater than base_speed" in config.errors["co2"] ) # ---------------------------------------------- # Temperature должна остаться рабочей. # ---------------------------------------------- assert config.temperature is not None assert ( config.temperature.hysteresis == 0.5 ) temperature_policy = ( TemperaturePolicy( config.temperature ) ) assert ( temperature_policy.heater_required( temperature=20, target_temp=24, heater_on=False, ) is True ) # ---------------------------------------------- # Elica Assist тоже не должна пострадать. # ---------------------------------------------- assert ( config.elica_assist is not None ) elica_assist = ( ElicaAutoAssistState( config.elica_assist ) ) assert elica_assist is not None # Ошибка должна быть только в CO2. assert set(config.errors) == { "co2", } print( "AUTO CONFIG ISOLATION TEST PASSED" ) if __name__ == "__main__": main()