From 81eb7f00e839438f2d751f234f5850866f00c13f Mon Sep 17 00:00:00 2001 From: David Baetge Date: Wed, 15 Nov 2023 00:33:00 +0100 Subject: [PATCH] Fixed rainRate reset. Updated gauge tile dayChange logic. GH-224 --- skins/weewx-wdc/includes/gauge-tile.inc | 3 +- skins/weewx-wdc/src/js/diagrams/d3/gauge.tsx | 26 ++++++++++++++++-- skins/weewx-wdc/src/js/live-updates.ts | 29 +++++++++++++++----- 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/skins/weewx-wdc/includes/gauge-tile.inc b/skins/weewx-wdc/includes/gauge-tile.inc index b898e727..ad9973d6 100644 --- a/skins/weewx-wdc/includes/gauge-tile.inc +++ b/skins/weewx-wdc/includes/gauge-tile.inc @@ -55,7 +55,8 @@ unit: "$get_unit_label($get_unit_for_obs($partial_obs, $partial_obs_key, $context))", rounding: $get_rounding($partial_obs, $partial_obs_key), properties: $get_gauge_diagram_props($partial_obs, $context), - label: "$obs.label[$partial_obs]" + label: "$obs.label[$partial_obs]", + dayChange: false, }
diff --git a/skins/weewx-wdc/src/js/diagrams/d3/gauge.tsx b/skins/weewx-wdc/src/js/diagrams/d3/gauge.tsx index bce10c87..dd341f0e 100644 --- a/skins/weewx-wdc/src/js/diagrams/d3/gauge.tsx +++ b/skins/weewx-wdc/src/js/diagrams/d3/gauge.tsx @@ -106,20 +106,35 @@ export const D3GaugeDiagram: FunctionComponent = ( // MQTT handling. const gaugeData = (window as any)[props.seriesName]; + // TODO: dayChange handling. const gaugeProxy = new Proxy(gaugeData, { set: function (target, key, value) { - console.log(`${String(key)} set to ${value}`); + //console.log(`${String(key)} set to ${value}`); target[key] = value; + console.log(`Set ${String(key)} to ${value}`); + + if (target.dayChange) { + console.log("dayChange gauge"); + } + + console.log(target); + if (String(key) === "current") { setCurrent(parseFloat(value)); } - if (String(key) === "min" && parseFloat(value) < min) { + if ( + String(key) === "min" && + (parseFloat(value) < min || target.dayChange) + ) { setMin(parseFloat(value)); } - if (String(key) === "max" && parseFloat(value) > max) { + if ( + String(key) === "max" && + (parseFloat(value) > max || target.dayChange) + ) { setMax(parseFloat(value)); } @@ -674,6 +689,11 @@ export const D3GaugeDiagram: FunctionComponent = ( -gaugeContainerDimensions.y + margin })` ); + + console.log("obs", props.obs); + console.log("current", current); + console.log("min", min); + console.log("max", max); }, [current, min, max, darkMode, dimensions]); return ( diff --git a/skins/weewx-wdc/src/js/live-updates.ts b/skins/weewx-wdc/src/js/live-updates.ts index af74bfb7..e1207a4d 100644 --- a/skins/weewx-wdc/src/js/live-updates.ts +++ b/skins/weewx-wdc/src/js/live-updates.ts @@ -77,11 +77,11 @@ const _updateStatTile = ( `day${observation[0].toUpperCase()}${observation.slice(1)}_${unitMQTT}` ]; - if (!sumValue) return; - - statTile.querySelector( - ".stat-title-obs-value .raw" - )!.innerHTML = `${parseFloat(sumValue).toFixed(rounding)}${unit}`; + if (sumValue) { + statTile.querySelector( + ".stat-title-obs-value .raw" + )!.innerHTML = `${parseFloat(sumValue).toFixed(rounding)}${unit}`; + } } else { // Use the current value. statTile.querySelector( @@ -256,6 +256,11 @@ const _updateStatTile = ( rainRate = parseFloat(payLoad["rainRate_cm_per_hour"]); } + // Ensure rainRate if reset in day change. + if (dayChange && rainRate === null) { + rainRate = 0; + } + if (rainRate === null) return; const rainRateUnit = statTile.getAttribute("data-unit-rain-rate")!; @@ -516,23 +521,33 @@ const onMessageArrived = (message: Message) => { `.diagram-tile.gauge[data-observation="${observation}"]` ); + // TODO: Min/Max reset on day change not working. if (gaugeTile) { const gaugeTileSeriesName = gaugeTile.getAttribute("data-test")!; (window as any)[gaugeTileSeriesName].current = payLoad[key]; + // Respect day change. + if (dayChange) { + (window as any)[gaugeTileSeriesName].dayChange = true; + } + if ( - payLoad[key] < (window as any)[gaugeTileSeriesName].min || + parseFloat(payLoad[key]) < + parseFloat((window as any)[gaugeTileSeriesName].min) || dayChange ) { (window as any)[gaugeTileSeriesName].min = payLoad[key]; } if ( - payLoad[key] > (window as any)[gaugeTileSeriesName].max || + parseFloat(payLoad[key]) > + parseFloat((window as any)[gaugeTileSeriesName].max) || dayChange ) { (window as any)[gaugeTileSeriesName].max = payLoad[key]; } + + (window as any)[gaugeTileSeriesName].dayChange = false; } if (statTile) {