Skip to content

Commit

Permalink
Merge pull request #212 from Daveiano/198-mqtt-day-reset
Browse files Browse the repository at this point in the history
Fixes GH-198
  • Loading branch information
Daveiano committed Nov 2, 2023
2 parents 0cc987e + 3344afb commit 435d74e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 19 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions skins/weewx-wdc/includes/html-head.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#errorCatcher Echo
#encoding UTF-8
#import html
#import datetime
#set $diagrams_config = $DisplayOptions.get("diagrams", {})
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
Expand Down Expand Up @@ -83,6 +84,7 @@
"Format_is": "$gettext('Format is')",
},
locale: "$get_locale()",
time: $datetime.datetime.now().timestamp()
};
</script>

Expand Down
16 changes: 8 additions & 8 deletions skins/weewx-wdc/includes/ui-shell.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
}
}
});
Expand Down
56 changes: 45 additions & 11 deletions skins/weewx-wdc/src/js/live-updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}`;
Expand Down Expand Up @@ -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}`;
Expand Down Expand Up @@ -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}`;
Expand All @@ -286,7 +287,8 @@ const _updateTableRow = (
unit: string,
value: number,
rounding: number,
payLoad: any
payLoad: any,
dayChange: boolean
) => {
// Update the main value.
tableRow.querySelector(
Expand Down Expand Up @@ -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}`;
Expand Down Expand Up @@ -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}`;
Expand Down Expand Up @@ -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}"]`
Expand All @@ -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];
}
}
Expand All @@ -526,7 +556,8 @@ const onMessageArrived = (message: Message) => {
newValue,
statTileRounding,
payLoad,
unitMQTT
unitMQTT,
dayChange
);
}

Expand Down Expand Up @@ -563,7 +594,8 @@ const onMessageArrived = (message: Message) => {
tableRowUnit,
newValue,
tableRowRounding,
payLoad
payLoad,
dayChange
);
}
}
Expand All @@ -587,3 +619,5 @@ client.connect({
useSSL: mqtt_ssl === "1",
reconnect: true,
});

alert("test 3");

0 comments on commit 435d74e

Please sign in to comment.