Update store types

This commit is contained in:
grove5_admin committed 2026-05-01 15:59:20 -07:00
1 parent c060fb79c0
commit fb23836070
3 files changed
+67 -45

No files matched your search

+40 -21
View File
@@ -108,15 +108,40 @@ function createStore() {
const now = Math.floor(Date.now() / 1000); const now = Math.floor(Date.now() / 1000);
// Update chamber live environment — ambient T/H is always safe to // ── Best-value source selection ───────────────────────────────────────
// publish (sampled before the heater fires, per BME690 datasheet), // Mirrors processor.py _select_temp_source / _select_rh_source so the
// even during burn-in. Gas-derived metrics (voc_ppb) are null during // UI shows the same corrected values the daemon uses for fingerprinting.
// burn-in per the daemon contract. //
chamber.environment.temp_c = ambient.temp_c; // Temperature priority:
chamber.environment.rh_pct = ambient.humidity_pct; // 1. BME690 corrected by baseline offset (established + bme_temp_offset known)
// 2. SCD43 directly (co2 valid + health.temp_ok)
// 3. BME690 raw (fallback)
//
// Humidity priority:
// 1. SCD43 (co2 valid — BME humidity drifts badly)
// 2. BME690 raw (fallback / colonization chamber)
const bmeOffset = payload.baseline?.bme_temp_offset ?? null;
const bestTemp =
(bmeOffset !== null && ambient.valid)
? ambient.temp_c - bmeOffset
: (payload.co2?.valid && payload.health.temp_ok)
? payload.co2.temp_c
: ambient.temp_c;
const bestRh = payload.co2?.valid ? payload.co2.humidity_pct : ambient.humidity_pct;
// Store both corrected display values and raw sensor readings.
// The advanced health panel uses the raw values for the BME vs SCD43 comparison.
chamber.environment.temp_c = bestTemp;
chamber.environment.rh_pct = bestRh;
chamber.environment.ambient_temp_c = ambient.temp_c;
chamber.environment.ambient_humidity_pct = ambient.humidity_pct;
if (payload.co2?.valid) { if (payload.co2?.valid) {
chamber.environment.co2_ppm = payload.co2.ppm; chamber.environment.co2_ppm = payload.co2.ppm;
chamber.environment.scd43_temp_c = payload.co2.temp_c;
chamber.environment.scd43_humidity_pct = payload.co2.humidity_pct;
} }
if (payload.co2e_ppm !== null) { if (payload.co2e_ppm !== null) {
chamber.environment.co2e_ppm = payload.co2e_ppm; chamber.environment.co2e_ppm = payload.co2e_ppm;
@@ -125,12 +150,6 @@ function createStore() {
chamber.environment.voc_ppb = payload.voc_ppb; chamber.environment.voc_ppb = payload.voc_ppb;
} }
// SCD43 cross-validation values (shown in advanced sensor health panel)
if (payload.co2?.valid) {
chamber.environment.scd43_temp_c = payload.co2.temp_c;
chamber.environment.scd43_humidity_pct = payload.co2.humidity_pct;
}
chamber.last_update_ts = now; chamber.last_update_ts = now;
chamber.burn_in = payload.burn_in; chamber.burn_in = payload.burn_in;
chamber.latestSweep = payload.sweep; chamber.latestSweep = payload.sweep;
@@ -139,17 +158,17 @@ function createStore() {
chamber.health = payload.health; chamber.health = payload.health;
chamber.co2e_confidence = payload.co2e_confidence; chamber.co2e_confidence = payload.co2e_confidence;
// Per-chamber history ring buffer. voc_ppb is undefined (not 0) when // Per-chamber history ring buffer — use corrected values throughout so
// the daemon didn't compute it — charts must distinguish "no data" // charts and VPD calculations reflect the same source as the live display.
// from "zero ppb". // voc_ppb is undefined (not 0) during burn-in — charts distinguish "no data".
const reading: EnvironmentReading = { const reading: EnvironmentReading = {
ts: now, ts: now,
temp_c: ambient.temp_c, temp_c: bestTemp,
rh_pct: ambient.humidity_pct, rh_pct: bestRh,
co2_ppm: payload.co2?.valid ? payload.co2.ppm : (chamber.environment.co2_ppm ?? 0), co2_ppm: payload.co2?.valid ? payload.co2.ppm : (chamber.environment.co2_ppm ?? 0),
co2e_ppm: payload.co2e_ppm ?? undefined, co2e_ppm: payload.co2e_ppm ?? undefined,
voc_ppb: payload.voc_ppb ?? 0, voc_ppb: payload.voc_ppb ?? 0,
vpd: calcVpd(ambient.temp_c, ambient.humidity_pct), vpd: calcVpd(bestTemp, bestRh),
}; };
chamber.history = [...chamber.history, reading]; chamber.history = [...chamber.history, reading];
if (chamber.history.length > HISTORY_MAX) { if (chamber.history.length > HISTORY_MAX) {
@@ -161,10 +180,10 @@ function createStore() {
// per-chamber shape. Fruiting is the canonical source because it // per-chamber shape. Fruiting is the canonical source because it
// carries SCD43 (real CO2). // carries SCD43 (real CO2).
if (chamber.type === 'fruiting') { if (chamber.type === 'fruiting') {
state.environment.live.temp_c = ambient.temp_c; state.environment.live.temp_c = bestTemp;
state.environment.live.rh_pct = ambient.humidity_pct; state.environment.live.rh_pct = bestRh;
state.environment.live.voc_ppb = payload.voc_ppb ?? state.environment.live.voc_ppb; state.environment.live.voc_ppb = payload.voc_ppb ?? state.environment.live.voc_ppb;
state.environment.live.vpd = calcVpd(ambient.temp_c, ambient.humidity_pct); state.environment.live.vpd = calcVpd(bestTemp, bestRh);
if (payload.co2?.valid) state.environment.live.co2_ppm = payload.co2.ppm; if (payload.co2?.valid) state.environment.live.co2_ppm = payload.co2.ppm;
state.environment.history = [...state.environment.history, reading]; state.environment.history = [...state.environment.history, reading];
+6 -1
View File
@@ -51,12 +51,17 @@ export type ChamberSlot = {
}; };
export type ChamberEnvironment = { export type ChamberEnvironment = {
/** Best available temperature — BME corrected by baseline offset, SCD43, or BME raw */
temp_c: number; temp_c: number;
/** Best available humidity — SCD43 when present, BME raw otherwise */
rh_pct: number; rh_pct: number;
co2_ppm?: number; // fruiting chamber (SCD43 direct) co2_ppm?: number; // fruiting chamber (SCD43 direct)
co2e_ppm?: number; // colonization chamber (gas-derived estimate) co2e_ppm?: number; // colonization chamber (gas-derived estimate)
voc_ppb: number; voc_ppb: number;
/** SCD43 cross-validation values — used in sensor health display */ /** Raw BME690 ambient readings — used in sensor health display */
ambient_temp_c?: number;
ambient_humidity_pct?: number;
/** SCD43 cross-validation readings — used in sensor health display */
scd43_temp_c?: number; scd43_temp_c?: number;
scd43_humidity_pct?: number; scd43_humidity_pct?: number;
}; };
+21 -23
View File
@@ -531,54 +531,54 @@
<table class="adv-table"> <table class="adv-table">
<thead> <thead>
<tr> <tr>
<th>Sensor</th> <th></th>
<th>BME690</th> <th>BME690 raw</th>
<th>SCD43</th> <th>SCD43</th>
<th>Delta</th> <th>Delta</th>
<th>Status</th> <th>In use</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td class="adv-row-label">Temperature</td> <td class="adv-row-label">Temperature</td>
<td class="mono">{ch.environment.temp_c.toFixed(1)}°C</td> <td class="mono">
{#if ch.environment.ambient_temp_c !== undefined}
{ch.environment.ambient_temp_c.toFixed(1)}°C
{:else}{ch.environment.temp_c.toFixed(1)}°C{/if}
</td>
<td class="mono"> <td class="mono">
{#if h.scd43_present && ch.environment.scd43_temp_c !== undefined} {#if h.scd43_present && ch.environment.scd43_temp_c !== undefined}
{ch.environment.scd43_temp_c.toFixed(1)}°C {ch.environment.scd43_temp_c.toFixed(1)}°C
{:else} {:else}<span class="muted">—</span>{/if}
<span class="muted">—</span>
{/if}
</td> </td>
<td class="mono"> <td class="mono">
{#if h.temp_delta !== null} {#if h.temp_delta !== null}
{h.temp_delta > 0 ? '+' : ''}{h.temp_delta.toFixed(1)}°C {h.temp_delta.toFixed(1)}°C
{:else}<span class="muted">—</span>{/if} {:else}<span class="muted">—</span>{/if}
</td> </td>
<td> <td>
<span class="htag" class:htag-ok={h.temp_ok} class:htag-warn={!h.temp_ok}> <span class="htag htag-ok">{ch.environment.temp_c.toFixed(1)}°C</span>
{h.temp_ok ? 'ok' : 'drift'}
</span>
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="adv-row-label">Humidity</td> <td class="adv-row-label">Humidity</td>
<td class="mono">{ch.environment.rh_pct.toFixed(0)}%</td> <td class="mono">
{#if ch.environment.ambient_humidity_pct !== undefined}
{ch.environment.ambient_humidity_pct.toFixed(0)}%
{:else}{ch.environment.rh_pct.toFixed(0)}%{/if}
</td>
<td class="mono"> <td class="mono">
{#if h.scd43_present && ch.environment.scd43_humidity_pct !== undefined} {#if h.scd43_present && ch.environment.scd43_humidity_pct !== undefined}
{ch.environment.scd43_humidity_pct.toFixed(0)}% {ch.environment.scd43_humidity_pct.toFixed(0)}%
{:else} {:else}<span class="muted">—</span>{/if}
<span class="muted">—</span>
{/if}
</td> </td>
<td class="mono"> <td class="mono">
{#if h.humidity_delta !== null} {#if h.humidity_delta !== null}
{h.humidity_delta > 0 ? '+' : ''}{h.humidity_delta.toFixed(1)}% {h.humidity_delta.toFixed(1)}%
{:else}<span class="muted">—</span>{/if} {:else}<span class="muted">—</span>{/if}
</td> </td>
<td> <td>
<span class="htag" class:htag-ok={h.humidity_ok} class:htag-warn={!h.humidity_ok}> <span class="htag htag-ok">{ch.environment.rh_pct.toFixed(0)}%</span>
{h.humidity_ok ? 'ok' : 'drift'}
</span>
</td> </td>
</tr> </tr>
{#if ch.type === 'fruiting' && ch.environment.co2_ppm !== undefined} {#if ch.type === 'fruiting' && ch.environment.co2_ppm !== undefined}
@@ -587,15 +587,13 @@
<td class="muted mono">—</td> <td class="muted mono">—</td>
<td class="mono">{ch.environment.co2_ppm.toFixed(0)} ppm</td> <td class="mono">{ch.environment.co2_ppm.toFixed(0)} ppm</td>
<td class="muted mono">—</td> <td class="muted mono">—</td>
<td> <td><span class="htag htag-ok">{ch.environment.co2_ppm.toFixed(0)} ppm</span></td>
<span class="htag htag-ok">{h.scd43_present ? 'ok' : 'absent'}</span>
</td>
</tr> </tr>
{/if} {/if}
</tbody> </tbody>
</table> </table>
{#if !h.scd43_present} {#if !h.scd43_present}
<p class="adv-note font-serif italic">SCD43 not detected — colonization chamber uses CO₂e estimate only.</p> <p class="adv-note font-serif italic">No SCD43 — colonization chamber uses BME690 for humidity and CO₂e estimate only.</p>
{/if} {/if}
</div> </div>
{/if} {/if}