fix config always assumed changed

This commit is contained in:
Empire Phoenix 2025-05-07 00:48:06 +02:00
parent bfc3fbc6e1
commit 171b130a29
4 changed files with 52 additions and 44 deletions

View File

@ -79,10 +79,11 @@ interface PlantConfig {
pump_cooldown_min: number, pump_cooldown_min: number,
pump_hour_start: number, pump_hour_start: number,
pump_hour_end: number, pump_hour_end: number,
sensor_a: boolean,
sensor_b: boolean, sensor_b: boolean,
max_consecutive_pump_count: number, max_consecutive_pump_count: number,
moisture_sensor_min_frequency?: number; moisture_sensor_min_frequency: number | null;
moisture_sensor_max_frequency?: number; moisture_sensor_max_frequency: number | null;
} }

View File

@ -14,7 +14,7 @@
} }
.progress { .progress {
height: 1.5em; height: 2.5em;
width: 100%; width: 100%;
background-color: #555; background-color: #555;
position: relative; position: relative;
@ -29,7 +29,7 @@
font-size: 0.8em; font-size: 0.8em;
position: absolute; position: absolute;
text-align: center; text-align: center;
top: 5px; top: 10px;
left: 0; left: 0;
right: 0; right: 0;
} }

View File

@ -205,18 +205,16 @@ export class Controller {
}) })
} }
downloadConfig() :Promise<void> { async downloadConfig(): Promise<void> {
controller.progressview.addIndeterminate("get_config", "Downloading Config") controller.progressview.addIndeterminate("get_config", "Downloading Config")
return fetch(PUBLIC_URL + "/get_config") const response = await fetch(PUBLIC_URL + "/get_config");
.then(response => response.json()) const loaded = await response.json();
.then(loaded => { var currentConfig = loaded as PlantControllerConfig;
var currentConfig = loaded as PlantControllerConfig; controller.setInitialConfig(currentConfig);
controller.setInitialConfig(currentConfig); controller.setConfig(currentConfig);
controller.setConfig(currentConfig); //sync json view initially
//sync json view initially controller.configChanged();
this.configChanged(); controller.progressview.removeProgress("get_config");
controller.progressview.removeProgress("get_config")
})
} }
setInitialConfig(currentConfig: PlantControllerConfig) { setInitialConfig(currentConfig: PlantControllerConfig) {
this.initialConfig = currentConfig this.initialConfig = currentConfig
@ -262,6 +260,7 @@ export class Controller {
var pretty = JSON.stringify(current, undefined, 0); var pretty = JSON.stringify(current, undefined, 0);
controller.submitView.setJson(pretty); controller.submitView.setJson(pretty);
if (deepEqual(current, controller.initialConfig)) { if (deepEqual(current, controller.initialConfig)) {
document.title = "PlantCtrl" document.title = "PlantCtrl"
} else { } else {
@ -471,36 +470,42 @@ export class Controller {
const controller = new Controller(); const controller = new Controller();
controller.progressview.removeProgress("rebooting"); controller.progressview.removeProgress("rebooting");
controller.progressview.addProgress("initial", 0, "read timezones");
controller.populateTimezones().then(_ => {
controller.progressview.addProgress("initial", 10, "read rtc");
controller.updateRTCData().then(_ => { const tasks = [
controller.progressview.addProgress("initial", 20, "read battery"); { task: controller.populateTimezones, displayString: "Populating Timezones" },
controller.updateBatteryData().then(_ => { { task: controller.updateRTCData, displayString: "Updating RTC Data" },
controller.progressview.addProgress("initial", 40, "read config"); { task: controller.updateBatteryData, displayString: "Updating Battery Data" },
controller.downloadConfig().then(_ => { { task: controller.downloadConfig, displayString: "Downloading Configuration" },
controller.progressview.addProgress("initial", 50, "read version"); { task: controller.version, displayString: "Fetching Version Information" },
controller.version().then(_ => { { task: controller.updateFileList, displayString: "Updating File List" },
controller.progressview.addProgress("initial", 70, "read filelist"); { task: controller.getBackupInfo, displayString: "Fetching Backup Information" },
controller.updateFileList().then(_ => { { task: controller.loadLogLocaleConfig, displayString: "Loading Log Localization Config" },
controller.progressview.addProgress("initial", 90, "read backupinfo"); { task: controller.loadTankInfo, displayString: "Loading Tank Information" },
controller.getBackupInfo().then(_ => { ];
controller.loadLogLocaleConfig().then(_ => {
controller.loadTankInfo().then(_ => { async function executeTasksSequentially() {
controller.progressview.removeProgress("initial") let current = 0;
}) for (const { task, displayString } of tasks) {
}) current++;
}) let ratio = current / tasks.length;
}) controller.progressview.addProgress("initial", ratio * 100, displayString);
}) try {
}); await task();
}); } catch (error) {
}); console.error(`Error executing task '${displayString}':`, error);
// Optionally, you can decide whether to continue or break on errors
break;
}
}
}
executeTasksSequentially().then(r => {
controller.progressview.removeProgress("initial")
}); });
//controller.measure_moisture();
controller.progressview.removeProgress("rebooting"); controller.progressview.removeProgress("rebooting");

View File

@ -183,6 +183,8 @@ export class PlantView {
getConfig(): PlantConfig { getConfig(): PlantConfig {
return { return {
// hardcoded for now
sensor_a: true,
mode: this.mode.value, mode: this.mode.value,
target_moisture: this.targetMoisture.valueAsNumber, target_moisture: this.targetMoisture.valueAsNumber,
pump_time_s: this.pumpTimeS.valueAsNumber, pump_time_s: this.pumpTimeS.valueAsNumber,
@ -191,8 +193,8 @@ export class PlantView {
pump_hour_end: +this.pumpHourEnd.value, pump_hour_end: +this.pumpHourEnd.value,
sensor_b: this.sensorBInstalled.checked, sensor_b: this.sensorBInstalled.checked,
max_consecutive_pump_count: this.maxConsecutivePumpCount.valueAsNumber, max_consecutive_pump_count: this.maxConsecutivePumpCount.valueAsNumber,
moisture_sensor_min_frequency: this.moistureSensorMinFrequency.valueAsNumber || undefined, moisture_sensor_min_frequency: this.moistureSensorMinFrequency.valueAsNumber || null,
moisture_sensor_max_frequency: this.moistureSensorMaxFrequency.valueAsNumber || undefined, moisture_sensor_max_frequency: this.moistureSensorMaxFrequency.valueAsNumber || null
}; };
} }
} }