Update store types
This commit is contained in:
1 parent
c060fb79c0
commit
fb23836070
3 files changed
+68
-46
No files matched your search
+41
-22
@@ -108,15 +108,40 @@ function createStore() {
|
||||
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
|
||||
// Update chamber live environment — ambient T/H is always safe to
|
||||
// publish (sampled before the heater fires, per BME690 datasheet),
|
||||
// even during burn-in. Gas-derived metrics (voc_ppb) are null during
|
||||
// burn-in per the daemon contract.
|
||||
chamber.environment.temp_c = ambient.temp_c;
|
||||
chamber.environment.rh_pct = ambient.humidity_pct;
|
||||
// ── Best-value source selection ───────────────────────────────────────
|
||||
// Mirrors processor.py _select_temp_source / _select_rh_source so the
|
||||
// UI shows the same corrected values the daemon uses for fingerprinting.
|
||||
//
|
||||
// Temperature priority:
|
||||
// 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) {
|
||||
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) {
|
||||
chamber.environment.co2e_ppm = payload.co2e_ppm;
|
||||
@@ -125,12 +150,6 @@ function createStore() {
|
||||
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.burn_in = payload.burn_in;
|
||||
chamber.latestSweep = payload.sweep;
|
||||
@@ -139,17 +158,17 @@ function createStore() {
|
||||
chamber.health = payload.health;
|
||||
chamber.co2e_confidence = payload.co2e_confidence;
|
||||
|
||||
// Per-chamber history ring buffer. voc_ppb is undefined (not 0) when
|
||||
// the daemon didn't compute it — charts must distinguish "no data"
|
||||
// from "zero ppb".
|
||||
// Per-chamber history ring buffer — use corrected values throughout so
|
||||
// charts and VPD calculations reflect the same source as the live display.
|
||||
// voc_ppb is undefined (not 0) during burn-in — charts distinguish "no data".
|
||||
const reading: EnvironmentReading = {
|
||||
ts: now,
|
||||
temp_c: ambient.temp_c,
|
||||
rh_pct: ambient.humidity_pct,
|
||||
temp_c: bestTemp,
|
||||
rh_pct: bestRh,
|
||||
co2_ppm: payload.co2?.valid ? payload.co2.ppm : (chamber.environment.co2_ppm ?? 0),
|
||||
co2e_ppm: payload.co2e_ppm ?? undefined,
|
||||
voc_ppb: payload.voc_ppb ?? 0,
|
||||
vpd: calcVpd(ambient.temp_c, ambient.humidity_pct),
|
||||
vpd: calcVpd(bestTemp, bestRh),
|
||||
};
|
||||
chamber.history = [...chamber.history, reading];
|
||||
if (chamber.history.length > HISTORY_MAX) {
|
||||
@@ -161,10 +180,10 @@ function createStore() {
|
||||
// per-chamber shape. Fruiting is the canonical source because it
|
||||
// carries SCD43 (real CO2).
|
||||
if (chamber.type === 'fruiting') {
|
||||
state.environment.live.temp_c = ambient.temp_c;
|
||||
state.environment.live.rh_pct = ambient.humidity_pct;
|
||||
state.environment.live.temp_c = bestTemp;
|
||||
state.environment.live.rh_pct = bestRh;
|
||||
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;
|
||||
|
||||
state.environment.history = [...state.environment.history, reading];
|
||||
|
||||
+6
-1
@@ -51,12 +51,17 @@ export type ChamberSlot = {
|
||||
};
|
||||
|
||||
export type ChamberEnvironment = {
|
||||
/** Best available temperature — BME corrected by baseline offset, SCD43, or BME raw */
|
||||
temp_c: number;
|
||||
/** Best available humidity — SCD43 when present, BME raw otherwise */
|
||||
rh_pct: number;
|
||||
co2_ppm?: number; // fruiting chamber (SCD43 direct)
|
||||
co2e_ppm?: number; // colonization chamber (gas-derived estimate)
|
||||
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_humidity_pct?: number;
|
||||
};
|
||||
|
||||
@@ -531,54 +531,54 @@
|
||||
<table class="adv-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Sensor</th>
|
||||
<th>BME690</th>
|
||||
<th></th>
|
||||
<th>BME690 raw</th>
|
||||
<th>SCD43</th>
|
||||
<th>Delta</th>
|
||||
<th>Status</th>
|
||||
<th>In use</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<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">
|
||||
{#if h.scd43_present && ch.environment.scd43_temp_c !== undefined}
|
||||
{ch.environment.scd43_temp_c.toFixed(1)}°C
|
||||
{:else}
|
||||
<span class="muted">—</span>
|
||||
{/if}
|
||||
{:else}<span class="muted">—</span>{/if}
|
||||
</td>
|
||||
<td class="mono">
|
||||
{#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}
|
||||
</td>
|
||||
<td>
|
||||
<span class="htag" class:htag-ok={h.temp_ok} class:htag-warn={!h.temp_ok}>
|
||||
{h.temp_ok ? 'ok' : 'drift'}
|
||||
</span>
|
||||
<span class="htag htag-ok">{ch.environment.temp_c.toFixed(1)}°C</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<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">
|
||||
{#if h.scd43_present && ch.environment.scd43_humidity_pct !== undefined}
|
||||
{ch.environment.scd43_humidity_pct.toFixed(0)}%
|
||||
{:else}
|
||||
<span class="muted">—</span>
|
||||
{/if}
|
||||
{:else}<span class="muted">—</span>{/if}
|
||||
</td>
|
||||
<td class="mono">
|
||||
{#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}
|
||||
</td>
|
||||
<td>
|
||||
<span class="htag" class:htag-ok={h.humidity_ok} class:htag-warn={!h.humidity_ok}>
|
||||
{h.humidity_ok ? 'ok' : 'drift'}
|
||||
</span>
|
||||
<span class="htag htag-ok">{ch.environment.rh_pct.toFixed(0)}%</span>
|
||||
</td>
|
||||
</tr>
|
||||
{#if ch.type === 'fruiting' && ch.environment.co2_ppm !== undefined}
|
||||
@@ -587,15 +587,13 @@
|
||||
<td class="muted mono">—</td>
|
||||
<td class="mono">{ch.environment.co2_ppm.toFixed(0)} ppm</td>
|
||||
<td class="muted mono">—</td>
|
||||
<td>
|
||||
<span class="htag htag-ok">{h.scd43_present ? 'ok' : 'absent'}</span>
|
||||
</td>
|
||||
<td><span class="htag htag-ok">{ch.environment.co2_ppm.toFixed(0)} ppm</span></td>
|
||||
</tr>
|
||||
{/if}
|
||||
</tbody>
|
||||
</table>
|
||||
{#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}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
Reference in new issue
Block a user