import 'diagnostic_entry.dart'; import 'temperature_sample.dart'; class MachineState { final double temperature; final double targetTemperature; final bool isHeating; final bool isBrewing; /// Steam input active (V9/V10 `pid 65535 0 0 0` marker). The firmware /// switches the boiler on/off around the steam setpoint and sends no PID /// output, so [heatingPower] is unknown while this is set. final bool isSteaming; final int shotTimer; final String connectionStatus; final String? commandError; final List temperatureHistory; final List temperatureSamples; final List diagnosticLog; final DateTime? lastTelemetryAt; final bool telemetryStale; final String transportName; final bool firmwareUpdating; final double firmwareProgress; final String firmwareUpdateStatus; // Second temperature sensor (group-head / inline sensor, when present) final double sensor2Temperature; final List sensor2TemperatureHistory; // Configuration Parameters final double preinfusionTime; final int preinfusionPower; final double brewTemperature; final double steamTemperature; // PID Parameters final double pidP; final double pidI; final double pidD; final double pidIWindDownMin; final double pidIWindDownMax; final int pidPollingInterval; // Statistics final int shotCounter; final int grinderCounter; // Pressure Profiling final int pressureStart; final int pressureEnd; final int pressurePeriod; // Real-time Power final double heatingPower; // 0.0 to 1.0 // Advanced Logic final bool valveClosedWhilePaused; final int proActivePercentage; final int autoShutoffMinutes; final bool autoShutoffEnabled; // tmrosdnbl – inactivity shut-off gate // Scheduling final bool wakeupEnabled; final String wakeupTime; final bool shutdownEnabled; final String shutdownTime; // Ionic 2 / Hardware features final bool preinfusionEnabled; final double preinfusionPauseTime; final int output0; final int output1; final int output2; final bool installedAsTimer; final bool powerButtonFlipsBack; // Firmware / compatibility final bool isLegacyV4Firmware; // V4 firmware uses scale=1 for pistrt/piprd instead of 1000 final String firmwareVersion; // Full uname string from device (e.g. "meCoffee V5.3.1") // Automation final int maxShotTime; // shtmx – stops shot after N seconds (0 = disabled) final bool continuousMode; // tmpcntns – keep heating without shot trigger MachineState({ this.temperature = 0.0, this.targetTemperature = 101.0, this.isHeating = false, this.isBrewing = false, this.isSteaming = false, this.shotTimer = 0, this.connectionStatus = 'Disconnected', this.commandError, this.temperatureHistory = const [], this.temperatureSamples = const [], this.diagnosticLog = const [], this.lastTelemetryAt, this.telemetryStale = true, this.transportName = '', this.firmwareUpdating = false, this.firmwareProgress = 0, this.firmwareUpdateStatus = '', this.sensor2Temperature = 0.0, this.sensor2TemperatureHistory = const [], this.preinfusionTime = 3.0, this.preinfusionPower = 100, this.brewTemperature = 101.0, this.steamTemperature = 125.0, this.pidP = 20.0, this.pidI = 0.3, this.pidD = 128.0, this.pidIWindDownMin = 0.0, this.pidIWindDownMax = 20.0, this.pidPollingInterval = 1000, this.shotCounter = 0, this.grinderCounter = 0, this.pressureStart = 100, this.pressureEnd = 100, this.pressurePeriod = 25, this.heatingPower = 0.0, this.valveClosedWhilePaused = false, this.proActivePercentage = 33, this.autoShutoffMinutes = 60, this.autoShutoffEnabled = false, this.wakeupEnabled = false, this.wakeupTime = "07:00", this.shutdownEnabled = false, this.shutdownTime = "22:00", this.preinfusionEnabled = true, this.preinfusionPauseTime = 3.0, this.output0 = 112, this.output1 = 98, this.output2 = 118, this.installedAsTimer = false, this.powerButtonFlipsBack = false, this.isLegacyV4Firmware = false, this.firmwareVersion = '', this.maxShotTime = 60, this.continuousMode = false, }); MachineState copyWith({ double? temperature, double? targetTemperature, bool? isHeating, bool? isBrewing, bool? isSteaming, int? shotTimer, String? connectionStatus, String? commandError, bool clearCommandError = false, List? temperatureHistory, List? temperatureSamples, List? diagnosticLog, DateTime? lastTelemetryAt, bool clearLastTelemetry = false, bool? telemetryStale, String? transportName, bool? firmwareUpdating, double? firmwareProgress, String? firmwareUpdateStatus, double? sensor2Temperature, List? sensor2TemperatureHistory, double? preinfusionTime, int? preinfusionPower, double? brewTemperature, double? steamTemperature, double? pidP, double? pidI, double? pidD, double? pidIWindDownMin, double? pidIWindDownMax, int? pidPollingInterval, int? shotCounter, int? grinderCounter, int? pressureStart, int? pressureEnd, int? pressurePeriod, double? heatingPower, bool? valveClosedWhilePaused, int? proActivePercentage, int? autoShutoffMinutes, bool? autoShutoffEnabled, bool? wakeupEnabled, String? wakeupTime, bool? shutdownEnabled, String? shutdownTime, bool? preinfusionEnabled, double? preinfusionPauseTime, int? output0, int? output1, int? output2, bool? installedAsTimer, bool? powerButtonFlipsBack, bool? isLegacyV4Firmware, String? firmwareVersion, int? maxShotTime, bool? continuousMode, }) { return MachineState( temperature: temperature ?? this.temperature, targetTemperature: targetTemperature ?? this.targetTemperature, isHeating: isHeating ?? this.isHeating, isBrewing: isBrewing ?? this.isBrewing, isSteaming: isSteaming ?? this.isSteaming, shotTimer: shotTimer ?? this.shotTimer, connectionStatus: connectionStatus ?? this.connectionStatus, commandError: clearCommandError ? null : commandError ?? this.commandError, temperatureHistory: temperatureHistory ?? this.temperatureHistory, temperatureSamples: temperatureSamples ?? this.temperatureSamples, diagnosticLog: diagnosticLog ?? this.diagnosticLog, lastTelemetryAt: clearLastTelemetry ? null : lastTelemetryAt ?? this.lastTelemetryAt, telemetryStale: telemetryStale ?? this.telemetryStale, transportName: transportName ?? this.transportName, firmwareUpdating: firmwareUpdating ?? this.firmwareUpdating, firmwareProgress: firmwareProgress ?? this.firmwareProgress, firmwareUpdateStatus: firmwareUpdateStatus ?? this.firmwareUpdateStatus, sensor2Temperature: sensor2Temperature ?? this.sensor2Temperature, sensor2TemperatureHistory: sensor2TemperatureHistory ?? this.sensor2TemperatureHistory, preinfusionTime: preinfusionTime ?? this.preinfusionTime, preinfusionPower: preinfusionPower ?? this.preinfusionPower, brewTemperature: brewTemperature ?? this.brewTemperature, steamTemperature: steamTemperature ?? this.steamTemperature, pidP: pidP ?? this.pidP, pidI: pidI ?? this.pidI, pidD: pidD ?? this.pidD, pidIWindDownMin: pidIWindDownMin ?? this.pidIWindDownMin, pidIWindDownMax: pidIWindDownMax ?? this.pidIWindDownMax, pidPollingInterval: pidPollingInterval ?? this.pidPollingInterval, shotCounter: shotCounter ?? this.shotCounter, grinderCounter: grinderCounter ?? this.grinderCounter, pressureStart: pressureStart ?? this.pressureStart, pressureEnd: pressureEnd ?? this.pressureEnd, pressurePeriod: pressurePeriod ?? this.pressurePeriod, heatingPower: heatingPower ?? this.heatingPower, valveClosedWhilePaused: valveClosedWhilePaused ?? this.valveClosedWhilePaused, proActivePercentage: proActivePercentage ?? this.proActivePercentage, autoShutoffMinutes: autoShutoffMinutes ?? this.autoShutoffMinutes, autoShutoffEnabled: autoShutoffEnabled ?? this.autoShutoffEnabled, wakeupEnabled: wakeupEnabled ?? this.wakeupEnabled, wakeupTime: wakeupTime ?? this.wakeupTime, shutdownEnabled: shutdownEnabled ?? this.shutdownEnabled, shutdownTime: shutdownTime ?? this.shutdownTime, preinfusionEnabled: preinfusionEnabled ?? this.preinfusionEnabled, preinfusionPauseTime: preinfusionPauseTime ?? this.preinfusionPauseTime, output0: output0 ?? this.output0, output1: output1 ?? this.output1, output2: output2 ?? this.output2, installedAsTimer: installedAsTimer ?? this.installedAsTimer, powerButtonFlipsBack: powerButtonFlipsBack ?? this.powerButtonFlipsBack, isLegacyV4Firmware: isLegacyV4Firmware ?? this.isLegacyV4Firmware, firmwareVersion: firmwareVersion ?? this.firmwareVersion, maxShotTime: maxShotTime ?? this.maxShotTime, continuousMode: continuousMode ?? this.continuousMode, ); } }