feat: add sensor combine mode with Min, Max, and Avg options, update web UI and configuration for multi-sensor support

This commit is contained in:
2026-05-29 11:22:12 +02:00
parent fbf97732a4
commit c9a96f37f0
5 changed files with 120 additions and 28 deletions

View File

@@ -141,6 +141,7 @@ export interface PlantConfig {
min_pump_current_ma: number,
max_pump_current_ma: number,
ignore_current_error: boolean,
sensor_combine_mode: string,
}
export interface PumpTestResult {

View File

@@ -29,6 +29,9 @@
.plantSensorEnabledOnly_ ${plantId} {
}
.plantBothSensorsOnly_ ${plantId} {
}
.plantHidden_ ${plantId} {
display: none;
}
@@ -48,6 +51,14 @@
<div class="plantkey">Sensor B installed:</div>
<input class="plantcheckbox" id="plant_${plantId}_sensor_b" type="checkbox">
</div>
<div class="flexcontainer plantBothSensorsOnly_${plantId}">
<div class="plantkey">Sensor Combine Mode:</div>
<select class="plantvalue" id="plant_${plantId}_sensor_combine_mode">
<option value="Min">Min</option>
<option value="Max">Max</option>
<option value="Avg">Average</option>
</select>
</div>
<div class="flexcontainer">
<div class="plantkey">
Mode:

View File

@@ -93,6 +93,7 @@ export class PlantView {
private readonly pumpHourEnd: HTMLSelectElement;
private readonly sensorAInstalled: HTMLInputElement;
private readonly sensorBInstalled: HTMLInputElement;
private readonly sensorCombineMode: HTMLSelectElement;
private readonly mode: HTMLSelectElement;
private readonly moistureA: HTMLElement;
private readonly moistureB: HTMLElement;
@@ -236,6 +237,14 @@ export class PlantView {
controller.configChanged()
}
this.sensorCombineMode = document.getElementById("plant_" + plantId + "_sensor_combine_mode") as HTMLSelectElement;
this.sensorCombineMode.onchange = function () {
controller.configChanged()
}
// Initial visibility update for sensor combine mode
this.updateSensorCombineModeState();
this.minPumpCurrentMa = document.getElementById("plant_" + plantId + "_min_pump_current_ma") as HTMLInputElement;
this.minPumpCurrentMa.onchange = function () {
controller.configChanged()
@@ -271,6 +280,19 @@ export class PlantView {
};
}
updateSensorCombineModeState() {
const bothActive = this.sensorAInstalled.checked && this.sensorBInstalled.checked;
const bothOnlyElements = document.getElementsByClassName("plantBothSensorsOnly_" + this.plantId);
for (const element of Array.from(bothOnlyElements)) {
if (bothActive) {
element.classList.remove("plantHidden_" + this.plantId);
} else {
element.classList.add("plantHidden_" + this.plantId);
}
}
this.sensorCombineMode.disabled = !bothActive;
}
updateVisibility(plantConfig: PlantConfig) {
let sensorOnly = document.getElementsByClassName("plantSensorEnabledOnly_" + this.plantId)
let pumpOnly = document.getElementsByClassName("plantPumpEnabledOnly_" + this.plantId)
@@ -324,6 +346,9 @@ export class PlantView {
// element.classList.add("plantHidden_" + this.plantId)
// }
// }
// Update sensor combine mode visibility based on whether both sensors are active
this.updateSensorCombineModeState();
}
setTestResult(result: PumpTestResult) {
@@ -354,6 +379,7 @@ export class PlantView {
this.pumpHourEnd.value = plantConfig.pump_hour_end.toString();
this.sensorBInstalled.checked = plantConfig.sensor_b;
this.sensorAInstalled.checked = plantConfig.sensor_a;
this.sensorCombineMode.value = plantConfig.sensor_combine_mode || "Min";
this.maxConsecutivePumpCount.value = plantConfig.max_consecutive_pump_count.toString();
this.minPumpCurrentMa.value = plantConfig.min_pump_current_ma.toString();
this.maxPumpCurrentMa.value = plantConfig.max_pump_current_ma.toString();
@@ -383,6 +409,7 @@ export class PlantView {
pump_hour_end: +this.pumpHourEnd.value,
sensor_b: this.sensorBInstalled.checked,
sensor_a: this.sensorAInstalled.checked,
sensor_combine_mode: this.sensorCombineMode.value,
max_consecutive_pump_count: this.maxConsecutivePumpCount.valueAsNumber,
moisture_sensor_min_frequency: this.moistureSensorMinFrequency.valueAsNumber || null,
moisture_sensor_max_frequency: this.moistureSensorMaxFrequency.valueAsNumber || null,