Skip to content

Commit

Permalink
added alert support for e0 #458
Browse files Browse the repository at this point in the history
  • Loading branch information
io53 committed Nov 13, 2024
1 parent e16c7da commit 3d43a9b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
16 changes: 16 additions & 0 deletions src/UnitHelper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,22 @@ export function getAlertRange(type) {
return { max: 0, min: -105 }
case "offline":
return { max: +Infinity, min: 120 }
case "co2":
return { max: 2500, min: 350 }
case "voc":
return { max: 500, min: 0 }
case "pm10":
return { max: 250, min: 0 }
case "pm25":
return { max: 250, min: 0 }
case "pm40":
return { max: 250, min: 0 }
case "pm100":
return { max: 250, min: 0 }
case "luminosity":
return { max: 10000, min: 0 }
case "sound":
return { max: 127, min: 0 }
default:
return { max: 100, min: 0 }
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/AlertItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AlertItem extends Component {
if (max === +Infinity) max = 900
return addVariablesInString(this.props.t("alert_offline_description"), [max / 60]);
}
var uh = getUnitHelper(type)
var uh = getUnitHelper(this.props.dataKey)
if (type !== "humidity") {
min = uh.value(min)
max = uh.value(max)
Expand Down Expand Up @@ -111,7 +111,7 @@ class AlertItem extends Component {
getMinMaxArr() {
var alert = this.state.alert;
if (!alert) return null;
var uh = getUnitHelper(this.props.type.toLowerCase())
var uh = getUnitHelper(this.props.dataKey)
if (this.props.type.toLowerCase() === "humidity")
return [alert.min, alert.max]
let val = [uh.value(alert.min), uh.value(alert.max)]
Expand All @@ -126,7 +126,7 @@ class AlertItem extends Component {
var alert = this.state.alert;
var type = this.props.type.toLowerCase();
var t = this.props.t
var uh = getUnitHelper(type)
var uh = getUnitHelper(this.props.dataKey)
var enabled = alert && alert.enabled;
var validRange = getAlertRange(type)
if (type === "temperature" || type === "pressure") {
Expand Down
17 changes: 14 additions & 3 deletions src/states/Sensor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -715,9 +715,20 @@ class Sensor extends Component {
return <div>{parts[0]}<a style={{ color: "teal" }} target="blank" href={t("cloud_ruuvi_link_url")}>{t("cloud_ruuvi_link")}</a>{parts[1]}</div>
})()}
</Box>}
{["temperature", "humidity", "pressure", "signal", "movement", "offline"].map(x => {
{["temperature", "humidity", "pressure", "signal", "movement", "offline", "co2", "voc", "pm10", "pm25", "pm40", "pm100", "luminosity", "sound"].map(x => {
if (!x) return null
let dataKey = x === "movement" ? "movementCounter" : x === "signal" ? "rssi" : x;
const dataKeyMapping = {
"movement": "movementCounter",
"signal": "rssi",
"pm10": "pm1p0",
"pm25": "pm2p5",
"pm40": "pm4p0",
"pm100": "pm10p0",
"luminosity": "illuminance",
"sound": "soundLevelAvg"
};

const dataKey = dataKeyMapping[x] || x;
let latestValue = this.getLatestReading()[dataKey]
if (latestValue === undefined && x !== "offline") return null;
var alert = this.getAlert(x)
Expand All @@ -729,7 +740,7 @@ class Sensor extends Component {
showDelay={sensorSubscription === "Business Starter"}
detailedTitle={detailedTitle}
detailedText={detailedText} detailedSubText={detailedSubText}
type={x} onChange={(a, prevEnabled) => this.updateAlert(a, prevEnabled)} />
type={x} dataKey={dataKey} onChange={(a, prevEnabled) => this.updateAlert(a, prevEnabled)} />
})}
</List>
</AccordionPanel>
Expand Down

0 comments on commit 3d43a9b

Please sign in to comment.