add ability to override frequency per plant and adjust timezone, fix missing workhour for plants
This commit is contained in:
@@ -69,6 +69,7 @@ interface PlantControllerConfig {
|
||||
tank: TankConfig,
|
||||
night_lamp: NightLampConfig,
|
||||
plants: PlantConfig[]
|
||||
timezone?: string,
|
||||
}
|
||||
|
||||
interface PlantConfig {
|
||||
@@ -80,6 +81,9 @@ interface PlantConfig {
|
||||
pump_hour_end: number,
|
||||
sensor_b: boolean,
|
||||
max_consecutive_pump_count: number,
|
||||
moisture_sensor_min_frequency?: number;
|
||||
moisture_sensor_max_frequency?: number;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@@ -65,6 +65,17 @@ export class Controller {
|
||||
console.log(error);
|
||||
});
|
||||
}
|
||||
|
||||
populateTimezones(): Promise<void> {
|
||||
return fetch('/timezones')
|
||||
.then(response => response.json())
|
||||
.then(json => json as string[])
|
||||
.then(timezones => {
|
||||
controller.timeView.timezones(timezones)
|
||||
})
|
||||
.catch(error => console.error('Error fetching timezones:', error));
|
||||
}
|
||||
|
||||
updateFileList() : Promise<void> {
|
||||
return fetch(PUBLIC_URL + "/files")
|
||||
.then(response => response.json())
|
||||
@@ -308,7 +319,8 @@ export class Controller {
|
||||
network: controller.networkView.getConfig(),
|
||||
tank: controller.tankView.getConfig(),
|
||||
night_lamp: controller.nightLampView.getConfig(),
|
||||
plants: controller.plantViews.getConfig()
|
||||
plants: controller.plantViews.getConfig(),
|
||||
timezone: controller.timeView.getTimeZone()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,6 +362,7 @@ export class Controller {
|
||||
this.networkView.setConfig(current.network);
|
||||
this.nightLampView.setConfig(current.night_lamp);
|
||||
this.plantViews.setConfig(current.plants);
|
||||
this.timeView.setTimeZone(current.timezone);
|
||||
}
|
||||
|
||||
measure_moisture() {
|
||||
@@ -459,30 +472,34 @@ export class Controller {
|
||||
}
|
||||
const controller = new Controller();
|
||||
controller.progressview.removeProgress("rebooting");
|
||||
controller.progressview.addProgress("initial", 0, "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")
|
||||
|
||||
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")
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
})
|
||||
})
|
||||
;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
//controller.measure_moisture();
|
||||
|
||||
|
@@ -59,9 +59,17 @@
|
||||
</div>
|
||||
<div class="flexcontainer">
|
||||
<div class="plantkey">Warn Pump Count:</div>
|
||||
<input class="plantvalue" id="plant_${plantId}_max_consecutive_pump_count" type="number" min="1" , max="50" ,
|
||||
<input class="plantvalue" id="plant_${plantId}_max_consecutive_pump_count" type="number" min="1" max="50" ,
|
||||
placeholder="10">
|
||||
</div>
|
||||
<div class="flexcontainer">
|
||||
<div class="plantkey">Min Frequency Override</div>
|
||||
<input class="plantvalue" id="plant_${plantId}_min_frequency" type="number" min="1000" max="25000">
|
||||
</div>
|
||||
<div class="flexcontainer">
|
||||
<div class="plantkey">Max Frequency Override</div>
|
||||
<input class="plantvalue" id="plant_${plantId}_max_frequency" type="number" min="1000" max="25000" >
|
||||
</div>
|
||||
|
||||
<div class="flexcontainer">
|
||||
<div class="plantkey">Sensor B installed:</div>
|
||||
|
@@ -1,4 +1,3 @@
|
||||
|
||||
const PLANT_COUNT = 8;
|
||||
|
||||
|
||||
@@ -43,6 +42,8 @@ export class PlantViews {
|
||||
}
|
||||
|
||||
export class PlantView {
|
||||
private readonly moistureSensorMinFrequency: HTMLInputElement;
|
||||
private readonly moistureSensorMaxFrequency: HTMLInputElement;
|
||||
private readonly plantId: number;
|
||||
private readonly plantDiv: HTMLDivElement;
|
||||
private readonly header: HTMLElement;
|
||||
@@ -136,6 +137,19 @@ export class PlantView {
|
||||
this.maxConsecutivePumpCount.onchange = function(){
|
||||
controller.configChanged()
|
||||
}
|
||||
|
||||
this.moistureSensorMinFrequency = document.getElementById("plant_"+plantId+"_min_frequency") as HTMLInputElement;
|
||||
this.moistureSensorMinFrequency.onchange = function(){
|
||||
controller.configChanged()
|
||||
}
|
||||
this.moistureSensorMinFrequency.onchange = () => {
|
||||
controller.configChanged();
|
||||
};
|
||||
|
||||
this.moistureSensorMaxFrequency = document.getElementById("plant_"+plantId+"_max_frequency") as HTMLInputElement;
|
||||
this.moistureSensorMaxFrequency.onchange = () => {
|
||||
controller.configChanged();
|
||||
};
|
||||
}
|
||||
|
||||
update(a: number, b: number) {
|
||||
@@ -159,23 +173,31 @@ export class PlantView {
|
||||
this.pumpCooldown.value = plantConfig.pump_cooldown_min.toString();
|
||||
this.pumpHourStart.value = plantConfig.pump_hour_start.toString();
|
||||
this.pumpHourEnd.value = plantConfig.pump_hour_end.toString();
|
||||
this.sensorBInstalled.checked = plantConfig.sensor_b
|
||||
this.sensorBInstalled.checked = plantConfig.sensor_b;
|
||||
this.maxConsecutivePumpCount.value = plantConfig.max_consecutive_pump_count.toString();
|
||||
|
||||
// Set new fields
|
||||
this.moistureSensorMinFrequency.value =
|
||||
plantConfig.moisture_sensor_min_frequency?.toString() || "";
|
||||
this.moistureSensorMaxFrequency.value =
|
||||
plantConfig.moisture_sensor_max_frequency?.toString() || "";
|
||||
}
|
||||
|
||||
getConfig() :PlantConfig {
|
||||
const rv:PlantConfig = {
|
||||
mode: this.mode.value,
|
||||
target_moisture: this.targetMoisture.valueAsNumber,
|
||||
pump_time_s: this.pumpTimeS.valueAsNumber,
|
||||
pump_cooldown_min: this.pumpCooldown.valueAsNumber,
|
||||
pump_hour_start: +this.pumpHourStart.value,
|
||||
pump_hour_end: +this.pumpHourEnd.value,
|
||||
sensor_b: this.sensorBInstalled.checked,
|
||||
max_consecutive_pump_count: this.maxConsecutivePumpCount.valueAsNumber
|
||||
}
|
||||
return rv
|
||||
}
|
||||
getConfig(): PlantConfig {
|
||||
const rv: PlantConfig = {
|
||||
mode: this.mode.value,
|
||||
target_moisture: this.targetMoisture.valueAsNumber,
|
||||
pump_time_s: this.pumpTimeS.valueAsNumber,
|
||||
pump_cooldown_min: this.pumpCooldown.valueAsNumber,
|
||||
pump_hour_start: +this.pumpHourStart.value,
|
||||
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,
|
||||
};
|
||||
return rv;
|
||||
}
|
||||
|
||||
setMoistureA(a: number) {
|
||||
this.moistureA.innerText = String(a);
|
||||
|
@@ -18,4 +18,11 @@
|
||||
<div id="timeview_browser_time" style="text-wrap: nowrap; flex-grow: 1;">Local time</div>
|
||||
</div>
|
||||
|
||||
<div style="display:flex">
|
||||
<span style="min-width: 50px;">Timezone:</span>
|
||||
<select id="timezone_select" style="text-wrap: nowrap; flex-grow: 1;">
|
||||
<option value="" disabled selected>Select Timezone</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<button id="timeview_time_upload">Store Browser time into esp and rtc</button>
|
||||
|
@@ -8,9 +8,14 @@ export class TimeView {
|
||||
auto_refresh: HTMLInputElement;
|
||||
controller: Controller;
|
||||
timer: NodeJS.Timeout | undefined;
|
||||
timezoneSelect: HTMLSelectElement;
|
||||
|
||||
constructor(controller:Controller) {
|
||||
(document.getElementById("timeview") as HTMLElement).innerHTML = require("./timeview.html")
|
||||
this.timezoneSelect = document.getElementById('timezone_select') as HTMLSelectElement;
|
||||
this.timezoneSelect.onchange = function(){
|
||||
controller.configChanged()
|
||||
}
|
||||
|
||||
this.auto_refresh = document.getElementById("timeview_auto_refresh") as HTMLInputElement;
|
||||
this.esp_time = document.getElementById("timeview_esp_time") as HTMLDivElement;
|
||||
@@ -44,4 +49,26 @@ export class TimeView {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
timezones(timezones: string[]) {
|
||||
timezones.forEach(tz => {
|
||||
const option = document.createElement('option');
|
||||
option.value = tz;
|
||||
option.textContent = tz;
|
||||
this.timezoneSelect.appendChild(option);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
getTimeZone() {
|
||||
return this.timezoneSelect.value;
|
||||
}
|
||||
|
||||
setTimeZone(timezone: string | undefined) {
|
||||
if (timezone != undefined) {
|
||||
this.timezoneSelect.value = timezone;
|
||||
} else {
|
||||
this.timezoneSelect.value = "UTC";
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user