From f50037dc1476bd38338e3b5cead7c051ef2ba572 Mon Sep 17 00:00:00 2001 From: io53 Date: Mon, 25 Mar 2024 00:01:17 +0200 Subject: [PATCH] #401 show last measured value under alert sliders --- src/components/AlertItem.js | 14 ++++++++++++-- src/states/Sensor.js | 6 ++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/components/AlertItem.js b/src/components/AlertItem.js index 7243915..33dd057 100644 --- a/src/components/AlertItem.js +++ b/src/components/AlertItem.js @@ -2,7 +2,7 @@ import { Box, ListItem } from "@chakra-ui/layout"; import { Switch } from "@chakra-ui/switch"; import React, { Component, Suspense } from "react"; import { withTranslation } from 'react-i18next'; -import { getAlertRange, getUnitHelper, localeNumber, round } from "../UnitHelper"; +import { getAlertRange, getDisplayValue, getUnitHelper, localeNumber, round } from "../UnitHelper"; import EditableText from "./EditableText"; import InputDialog from "./InputDialog"; import RangeInputDialog from "./RangeInputDialog"; @@ -148,6 +148,9 @@ class AlertItem extends Component { + const getUnit = () => { + return type !== "movement" && type !== "signal" && type !== "offline" ? ` ${type === "humidity" ? "%" : uh.unit}` : "" + } return ( @@ -176,9 +179,16 @@ class AlertItem extends Component { }> this.setAlert({ ...alert, min: v[0], max: v[1] }, type, alert ? alert.enabled : false, !final)} /> + {this.props.latestValue !== undefined && +
+ + {t("latest_measured_value").replace(/{(.*?)}/, getDisplayValue(this.props.type.toLowerCase(), this.props.latestValue))} {getUnit()} + +
+ } } - {this.props.showDelay && type !== "offline" && + {this.props.showDelay && type !== "offline" && {delaySetting()} diff --git a/src/states/Sensor.js b/src/states/Sensor.js index 559a67d..d42c6c1 100644 --- a/src/states/Sensor.js +++ b/src/states/Sensor.js @@ -708,11 +708,13 @@ class Sensor extends Component { } {["temperature", "humidity", "pressure", "signal", "movement", ...[["Free", "Basic"].includes(sensorSubscription) ? null : "offline"]].map(x => { if (!x) return null - let dataKey = x === "movement" ? "movementCounter" : "signal" ? "rssi" : x; - if (this.getLatestReading()[dataKey] === undefined) return null; + let dataKey = x === "movement" ? "movementCounter" : x === "signal" ? "rssi" : x; + let latestValue = this.getLatestReading()[dataKey] + if (latestValue === undefined) return null; var alert = this.getAlert(x) let key = alert ? alert.min + "" + alert.max + "" + alert.enabled.toString() + "" + alert.description : x return