diff --git a/changelog.md b/changelog.md index e0291d3..c3c214f 100644 --- a/changelog.md +++ b/changelog.md @@ -728,6 +728,7 @@ See https://github.com/Daveiano/weewx-wdc/compare/v3.2.0...11eed6b3#diff-ba225fb - Bugfix: Manifest.json does not use base_path GH-197 - Bugfix: Tool Tip out of Scope GH-194 - Bugfix: Observations with $current N/A values are not shown anymore in stat-tiles/conditions table on day page GH-188 +- Bugfix: Day Mix/Max Values in Tiles Do Not reset at Midnight GH-198 - Bugfix: Fixed a bug where markers where not shown if multiple were added in a single unit chart GH-216 - Added `show_min_max` configuration to gauges config, added ordinal display for windDir gauge min/max - Only show 3 decimals for the geocode provided by weewx-forecast GH-191 diff --git a/skins/weewx-wdc/includes/html-head.inc b/skins/weewx-wdc/includes/html-head.inc index e0da36e..35db26f 100644 --- a/skins/weewx-wdc/includes/html-head.inc +++ b/skins/weewx-wdc/includes/html-head.inc @@ -2,6 +2,7 @@ #errorCatcher Echo #encoding UTF-8 #import html +#import datetime #set $diagrams_config = $DisplayOptions.get("diagrams", {}) @@ -83,6 +84,7 @@ "Format_is": "$gettext('Format is')", }, locale: "$get_locale()", + time: $datetime.datetime.now().timestamp() }; diff --git a/skins/weewx-wdc/includes/ui-shell.inc b/skins/weewx-wdc/includes/ui-shell.inc index caab089..44d7c5c 100644 --- a/skins/weewx-wdc/includes/ui-shell.inc +++ b/skins/weewx-wdc/includes/ui-shell.inc @@ -392,8 +392,8 @@ // Change the icons inside the button based on previous settings if ( - localStorage.getItem("color-theme") === "dark" || - (!("color-theme" in localStorage) && + localStorage.getItem("weewx.weewx_wdc.color-theme") === "dark" || + (!("weewx.weewx_wdc.color-theme" in localStorage) && window.matchMedia("(prefers-color-scheme: dark)").matches) ) { document.documentElement.classList.add("dark"); @@ -419,23 +419,23 @@ }); // if set via local storage previously - if (localStorage.getItem("color-theme")) { - if (localStorage.getItem("color-theme") === "light") { + if (localStorage.getItem("weewx.weewx_wdc.color-theme")) { + if (localStorage.getItem("weewx.weewx_wdc.color-theme") === "light") { document.documentElement.classList.add("dark"); - localStorage.setItem("color-theme", "dark"); + localStorage.setItem("weewx.weewx_wdc.color-theme", "dark"); } else { document.documentElement.classList.remove("dark"); - localStorage.setItem("color-theme", "light"); + localStorage.setItem("weewx.weewx_wdc.color-theme", "light"); } // if NOT set via local storage previously } else { if (document.documentElement.classList.contains("dark")) { document.documentElement.classList.remove("dark"); - localStorage.setItem("color-theme", "light"); + localStorage.setItem("weewx.weewx_wdc.color-theme", "light"); } else { document.documentElement.classList.add("dark"); - localStorage.setItem("color-theme", "dark"); + localStorage.setItem("weewx.weewx_wdc.color-theme", "dark"); } } }); diff --git a/skins/weewx-wdc/src/js/live-updates.ts b/skins/weewx-wdc/src/js/live-updates.ts index 094f620..93526bc 100644 --- a/skins/weewx-wdc/src/js/live-updates.ts +++ b/skins/weewx-wdc/src/js/live-updates.ts @@ -62,7 +62,8 @@ const _updateStatTile = ( value: number, rounding: number, payLoad: any, - unitMQTT: string + unitMQTT: string, + dayChange: boolean ) => { // Update the main value. const sumObs = statTile @@ -133,7 +134,7 @@ const _updateStatTile = ( ? min!.querySelector(".stat-value span.value")!.innerHTML : ""; - if (min && payLoad[key] < parseFloat(minValue)) { + if (min && (payLoad[key] < parseFloat(minValue) || dayChange)) { min.querySelector(".stat-value span.value")!.textContent = `${parseFloat( payLoad[key] ).toFixed(rounding)}${unit}`; @@ -185,7 +186,7 @@ const _updateStatTile = ( ? max!.querySelector(".stat-value span.value")!.innerHTML : ""; - if (max && payLoad[key] > parseFloat(maxValue)) { + if (max && (payLoad[key] > parseFloat(maxValue) || dayChange)) { max.querySelector(".stat-value span.value")!.textContent = `${parseFloat( payLoad[key] ).toFixed(rounding)}${unit}`; @@ -271,7 +272,7 @@ const _updateStatTile = ( )!.textContent = `${rainRate.toFixed(rounding)}${rainRateUnit}`; } - if (rainRateMax && rainRate > parseFloat(rainRateMaxValue)) { + if (rainRateMax && (rainRate > parseFloat(rainRateMaxValue) || dayChange)) { rainRateMax.querySelector( ".stat-value span.value" )!.textContent = `${rainRate.toFixed(rounding)}${rainRateUnit}`; @@ -286,7 +287,8 @@ const _updateTableRow = ( unit: string, value: number, rounding: number, - payLoad: any + payLoad: any, + dayChange: boolean ) => { // Update the main value. tableRow.querySelector( @@ -333,7 +335,7 @@ const _updateTableRow = ( )!, minValue = minValueSpan.innerHTML; - if (min && payLoad[key] < parseFloat(minValue)) { + if (min && (payLoad[key] < parseFloat(minValue) || dayChange)) { minValueSpan.textContent = `${parseFloat(payLoad[key]).toFixed( rounding )}${unit}`; @@ -380,7 +382,8 @@ const _updateTableRow = ( "bx-structured-list-cell.cell-max > span" )!, maxValue = maxValueSpan.innerHTML; - if (max && payLoad[key] > parseFloat(maxValue)) { + + if (max && (payLoad[key] > parseFloat(maxValue) || dayChange)) { maxValueSpan.textContent = `${parseFloat(payLoad[key]).toFixed( rounding )}${unit}`; @@ -478,6 +481,27 @@ const onMessageArrived = (message: Message) => { const observation = keySplitted[0]; const unitMQTT = _getUnitFromMQTTProp(keySplitted); + const lastUpdate_ts = localStorage.getItem( + `weewx.weewx_wdc.mqtt-last-udpate-${key}` + ), + lastUpdate_formatted = lastUpdate_ts + ? dayjs.unix(parseInt(lastUpdate_ts)).format("YYYY-MM-DD") + : null; + let dayChange = false; + + // Day changed, reset min/max/sum. + if ( + lastUpdate_ts && + lastUpdate_formatted !== dayjs.unix(payLoad.dateTime).format("YYYY-MM-DD") + ) { + dayChange = true; + } + + localStorage.setItem( + `weewx.weewx_wdc.mqtt-last-udpate-${key}`, + payLoad.dateTime + ); + // Alternative layout. const statTile = document.querySelector( `.stat-tile[data-observation="${observation}"]` @@ -496,11 +520,17 @@ const onMessageArrived = (message: Message) => { const gaugeTileSeriesName = gaugeTile.getAttribute("data-test")!; (window as any)[gaugeTileSeriesName].current = payLoad[key]; - if (payLoad[key] < (window as any)[gaugeTileSeriesName].min) { + if ( + payLoad[key] < (window as any)[gaugeTileSeriesName].min || + dayChange + ) { (window as any)[gaugeTileSeriesName].min = payLoad[key]; } - if (payLoad[key] > (window as any)[gaugeTileSeriesName].max) { + if ( + payLoad[key] > (window as any)[gaugeTileSeriesName].max || + dayChange + ) { (window as any)[gaugeTileSeriesName].max = payLoad[key]; } } @@ -526,7 +556,8 @@ const onMessageArrived = (message: Message) => { newValue, statTileRounding, payLoad, - unitMQTT + unitMQTT, + dayChange ); } @@ -563,7 +594,8 @@ const onMessageArrived = (message: Message) => { tableRowUnit, newValue, tableRowRounding, - payLoad + payLoad, + dayChange ); } } @@ -587,3 +619,5 @@ client.connect({ useSSL: mqtt_ssl === "1", reconnect: true, }); + +alert("test 3");