Add firmware build timestamp support for sensors; update detection workflows and UI accordingly.
This commit is contained in:
@@ -1,7 +1,14 @@
|
||||
import {DetectionPlant, Detection, PlantConfig, PumpTestResult} from "./api";
|
||||
import {Detection, DetectionPlant, DetectionRequest, PlantConfig, PumpTestResult} from "./api";
|
||||
|
||||
export const PLANT_COUNT = 8;
|
||||
|
||||
/** Format a firmware build timestamp (minutes since Unix epoch) as a human-readable date/time. */
|
||||
function formatBuildMinutes(buildMinutes: number | null): string {
|
||||
if (buildMinutes === null) return "not detected";
|
||||
if (buildMinutes === 0) return "detected (no timestamp)";
|
||||
const ms = buildMinutes * 60 * 1000;
|
||||
return new Date(ms).toISOString().replace("T", " ").slice(0, 16) + " UTC";
|
||||
}
|
||||
|
||||
import {Controller} from "./main";
|
||||
|
||||
@@ -79,6 +86,8 @@ export class PlantView {
|
||||
private readonly mode: HTMLSelectElement;
|
||||
private readonly moistureA: HTMLElement;
|
||||
private readonly moistureB: HTMLElement;
|
||||
private readonly sensorAFwBuild: HTMLElement;
|
||||
private readonly sensorBFwBuild: HTMLElement;
|
||||
private readonly maxConsecutivePumpCount: HTMLInputElement;
|
||||
private readonly minPumpCurrentMa: HTMLInputElement;
|
||||
private readonly maxPumpCurrentMa: HTMLInputElement;
|
||||
@@ -109,6 +118,8 @@ export class PlantView {
|
||||
|
||||
this.moistureA = document.getElementById("plant_" + plantId + "_moisture_a")! as HTMLElement;
|
||||
this.moistureB = document.getElementById("plant_" + plantId + "_moisture_b")! as HTMLElement;
|
||||
this.sensorAFwBuild = document.getElementById("plant_" + plantId + "_sensor_a_fw_build")! as HTMLElement;
|
||||
this.sensorBFwBuild = document.getElementById("plant_" + plantId + "_sensor_b_fw_build")! as HTMLElement;
|
||||
|
||||
this.pump_test_current_max = document.getElementById("plant_" + plantId + "_pump_test_current_max")! as HTMLElement;
|
||||
this.pump_test_current_min = document.getElementById("plant_" + plantId + "_pump_test_current_min")! as HTMLElement;
|
||||
@@ -124,7 +135,7 @@ export class PlantView {
|
||||
|
||||
this.testSensorAButton = document.getElementById("plant_" + plantId + "_test_sensor_a")! as HTMLButtonElement;
|
||||
this.testSensorAButton.onclick = () => {
|
||||
const detection: Detection = {
|
||||
const detection: DetectionRequest = {
|
||||
plant: Array.from({length: PLANT_COUNT}, (_v, idx) => ({
|
||||
sensor_a: idx === plantId,
|
||||
sensor_b: false,
|
||||
@@ -135,7 +146,7 @@ export class PlantView {
|
||||
|
||||
this.testSensorBButton = document.getElementById("plant_" + plantId + "_test_sensor_b")! as HTMLButtonElement;
|
||||
this.testSensorBButton.onclick = () => {
|
||||
const detection: Detection = {
|
||||
const detection: DetectionRequest = {
|
||||
plant: Array.from({length: PLANT_COUNT}, (_v, idx) => ({
|
||||
sensor_a: false,
|
||||
sensor_b: idx === plantId,
|
||||
@@ -360,19 +371,23 @@ export class PlantView {
|
||||
}
|
||||
|
||||
setDetectionResult(plantResult: DetectionPlant) {
|
||||
console.log("setDetectionResult plantResult: " + plantResult.sensor_a + " " + plantResult.sensor_b)
|
||||
const sensorADetected = plantResult.sensor_a !== null;
|
||||
const sensorBDetected = plantResult.sensor_b !== null;
|
||||
console.log("setDetectionResult plantResult: a=" + plantResult.sensor_a + " b=" + plantResult.sensor_b);
|
||||
var changed = false;
|
||||
if (this.sensorAInstalled.checked != plantResult.sensor_a) {
|
||||
if (this.sensorAInstalled.checked != sensorADetected) {
|
||||
changed = true;
|
||||
this.sensorAInstalled.checked = plantResult.sensor_a;
|
||||
this.sensorAInstalled.checked = sensorADetected;
|
||||
}
|
||||
if (this.sensorBInstalled.checked != plantResult.sensor_b) {
|
||||
if (this.sensorBInstalled.checked != sensorBDetected) {
|
||||
changed = true;
|
||||
this.sensorBInstalled.checked = plantResult.sensor_b;
|
||||
this.sensorBInstalled.checked = sensorBDetected;
|
||||
}
|
||||
if (changed) {
|
||||
this.controller.configChanged();
|
||||
}
|
||||
|
||||
this.sensorAFwBuild.innerText = formatBuildMinutes(plantResult.sensor_a);
|
||||
this.sensorBFwBuild.innerText = formatBuildMinutes(plantResult.sensor_b);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user