diff --git a/rust/src_webpack/src/api.ts b/rust/src_webpack/src/api.ts index 09c34f3..4e67279 100644 --- a/rust/src_webpack/src/api.ts +++ b/rust/src_webpack/src/api.ts @@ -79,10 +79,11 @@ interface PlantConfig { pump_cooldown_min: number, pump_hour_start: number, pump_hour_end: number, + sensor_a: boolean, sensor_b: boolean, max_consecutive_pump_count: number, - moisture_sensor_min_frequency?: number; - moisture_sensor_max_frequency?: number; + moisture_sensor_min_frequency: number | null; + moisture_sensor_max_frequency: number | null; } diff --git a/rust/src_webpack/src/main.html b/rust/src_webpack/src/main.html index 33f82cc..8716f63 100644 --- a/rust/src_webpack/src/main.html +++ b/rust/src_webpack/src/main.html @@ -14,7 +14,7 @@ } .progress { - height: 1.5em; + height: 2.5em; width: 100%; background-color: #555; position: relative; @@ -29,7 +29,7 @@ font-size: 0.8em; position: absolute; text-align: center; - top: 5px; + top: 10px; left: 0; right: 0; } diff --git a/rust/src_webpack/src/main.ts b/rust/src_webpack/src/main.ts index dd4dcec..ab3fc44 100644 --- a/rust/src_webpack/src/main.ts +++ b/rust/src_webpack/src/main.ts @@ -205,18 +205,16 @@ export class Controller { }) } - downloadConfig() :Promise { + async downloadConfig(): Promise { controller.progressview.addIndeterminate("get_config", "Downloading Config") - return fetch(PUBLIC_URL + "/get_config") - .then(response => response.json()) - .then(loaded => { - var currentConfig = loaded as PlantControllerConfig; - controller.setInitialConfig(currentConfig); - controller.setConfig(currentConfig); - //sync json view initially - this.configChanged(); - controller.progressview.removeProgress("get_config") - }) + const response = await fetch(PUBLIC_URL + "/get_config"); + const loaded = await response.json(); + var currentConfig = loaded as PlantControllerConfig; + controller.setInitialConfig(currentConfig); + controller.setConfig(currentConfig); + //sync json view initially + controller.configChanged(); + controller.progressview.removeProgress("get_config"); } setInitialConfig(currentConfig: PlantControllerConfig) { this.initialConfig = currentConfig @@ -262,6 +260,7 @@ export class Controller { var pretty = JSON.stringify(current, undefined, 0); controller.submitView.setJson(pretty); + if (deepEqual(current, controller.initialConfig)) { document.title = "PlantCtrl" } else { @@ -471,36 +470,42 @@ export class Controller { const controller = new Controller(); controller.progressview.removeProgress("rebooting"); -controller.progressview.addProgress("initial", 0, "read timezones"); -controller.populateTimezones().then(_ => { - controller.progressview.addProgress("initial", 10, "read rtc"); - controller.updateRTCData().then(_ => { - controller.progressview.addProgress("initial", 20, "read battery"); - controller.updateBatteryData().then(_ => { - controller.progressview.addProgress("initial", 40, "read config"); - controller.downloadConfig().then(_ => { - controller.progressview.addProgress("initial", 50, "read version"); - controller.version().then(_ => { - controller.progressview.addProgress("initial", 70, "read filelist"); - controller.updateFileList().then(_ => { - controller.progressview.addProgress("initial", 90, "read backupinfo"); - controller.getBackupInfo().then(_ => { - controller.loadLogLocaleConfig().then(_ => { - controller.loadTankInfo().then(_ => { - controller.progressview.removeProgress("initial") - }) - }) - }) - }) - }) - }); - }); - }); + + + +const tasks = [ + { task: controller.populateTimezones, displayString: "Populating Timezones" }, + { task: controller.updateRTCData, displayString: "Updating RTC Data" }, + { task: controller.updateBatteryData, displayString: "Updating Battery Data" }, + { task: controller.downloadConfig, displayString: "Downloading Configuration" }, + { task: controller.version, displayString: "Fetching Version Information" }, + { task: controller.updateFileList, displayString: "Updating File List" }, + { task: controller.getBackupInfo, displayString: "Fetching Backup Information" }, + { task: controller.loadLogLocaleConfig, displayString: "Loading Log Localization Config" }, + { task: controller.loadTankInfo, displayString: "Loading Tank Information" }, +]; + +async function executeTasksSequentially() { + 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"); diff --git a/rust/src_webpack/src/plant.ts b/rust/src_webpack/src/plant.ts index e44ad7a..e042bf5 100644 --- a/rust/src_webpack/src/plant.ts +++ b/rust/src_webpack/src/plant.ts @@ -183,6 +183,8 @@ export class PlantView { getConfig(): PlantConfig { return { + // hardcoded for now + sensor_a: true, mode: this.mode.value, target_moisture: this.targetMoisture.valueAsNumber, pump_time_s: this.pumpTimeS.valueAsNumber, @@ -191,8 +193,8 @@ export class PlantView { pump_hour_end: +this.pumpHourEnd.value, sensor_b: this.sensorBInstalled.checked, max_consecutive_pump_count: this.maxConsecutivePumpCount.valueAsNumber, - moisture_sensor_min_frequency: this.moistureSensorMinFrequency.valueAsNumber || undefined, - moisture_sensor_max_frequency: this.moistureSensorMaxFrequency.valueAsNumber || undefined, + moisture_sensor_min_frequency: this.moistureSensorMinFrequency.valueAsNumber || null, + moisture_sensor_max_frequency: this.moistureSensorMaxFrequency.valueAsNumber || null }; } } \ No newline at end of file