added h2s lel and o2 to the device status readings on the devices dashboard
This commit is contained in:
parent
1e2003a541
commit
9e3ce3c00d
2 changed files with 101 additions and 30 deletions
|
|
@ -143,6 +143,8 @@ export default function Devices() {
|
|||
const [hasCo2, setHasCo2] = useState(false)
|
||||
const [hasNo2, setHasNo2] = useState(false)
|
||||
const [hasO2, setHasO2] = useState(false)
|
||||
const [hasLel, setHasLel] = useState(false)
|
||||
const [hasH2S, setHasH2S] = useState(false)
|
||||
|
||||
const [groupsLoading, setGroupsLoading] = useState(false)
|
||||
const [groups, setGroups] = useState<Group[]>([]);
|
||||
|
|
@ -296,16 +298,34 @@ export default function Devices() {
|
|||
|
||||
const doesDeviceHaveO2 = (device: pond.Device) => {
|
||||
if (device.status?.o2?.ppm && device.status?.o2?.timestamp) {
|
||||
if (device.status.sen5x?.timestamp) {
|
||||
const now = new Date();
|
||||
const oneDayAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000);
|
||||
if (compareTimestamps(device.status.o2?.timestamp, oneDayAgo.toISOString()) > 0) {
|
||||
return true
|
||||
}
|
||||
} else {
|
||||
return false
|
||||
const now = new Date();
|
||||
const oneDayAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000);
|
||||
if (compareTimestamps(device.status.o2?.timestamp, oneDayAgo.toISOString()) > 0) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
const doesDeviceHaveLel = (device: pond.Device) => {
|
||||
if (device.status?.lel?.ppm && device.status?.lel?.timestamp) {
|
||||
const now = new Date();
|
||||
const oneDayAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000);
|
||||
if (compareTimestamps(device.status.lel?.timestamp, oneDayAgo.toISOString()) > 0) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
const doesDeviceHaveH2S = (device: pond.Device) => {
|
||||
if (device.status?.h2s?.ppm && device.status?.h2s?.timestamp) {
|
||||
const now = new Date();
|
||||
const oneDayAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000);
|
||||
if (compareTimestamps(device.status.h2s?.timestamp, oneDayAgo.toISOString()) > 0) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
@ -486,6 +506,8 @@ export default function Devices() {
|
|||
let hasCo = false
|
||||
let hasCo2 = false
|
||||
let hasNo2 = false
|
||||
let hasLel = false
|
||||
let hasH2S = false
|
||||
resp.data.devices.forEach(device => {
|
||||
setHasPlenums(doesDeviceHavePlenum(device))
|
||||
if (doesDeviceHavePlenum(device)) hasPlenum = true
|
||||
|
|
@ -495,6 +517,8 @@ export default function Devices() {
|
|||
if (doesDeviceHaveCo(device)) hasCo = true
|
||||
if (doesDeviceHaveCo2(device)) hasCo2 = true
|
||||
if (doesDeviceHaveNo2(device)) hasNo2 = true
|
||||
if (doesDeviceHaveLel(device)) hasLel = true
|
||||
if (doesDeviceHaveH2S(device)) hasH2S = true
|
||||
newDevices.push(Device.create(device))
|
||||
})
|
||||
setHasPlenums(hasPlenum)
|
||||
|
|
@ -503,6 +527,8 @@ export default function Devices() {
|
|||
setHasCo(hasCo)
|
||||
setHasCo2(hasCo2)
|
||||
setHasNo2(hasNo2)
|
||||
setHasLel(hasLel)
|
||||
setHasH2S(hasH2S)
|
||||
setDevices(newDevices)
|
||||
setTotal(resp.data.total)
|
||||
}).finally(() => {
|
||||
|
|
@ -774,6 +800,42 @@ export default function Devices() {
|
|||
}
|
||||
})
|
||||
}
|
||||
if (hasLel && !groupGas) {
|
||||
columns.push({
|
||||
title: "LEL",
|
||||
render: (device: Device) => {
|
||||
if (device.status.lel) {
|
||||
return (
|
||||
<Box sx={{ marginLeft: 1 }}>
|
||||
<StatusGas device={device} gasType={"lel"} showTimestamp={showTimestamp} />
|
||||
</Box>
|
||||
)
|
||||
} else {
|
||||
return (
|
||||
<></>
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
if (hasH2S && !groupGas) {
|
||||
columns.push({
|
||||
title: "H2S",
|
||||
render: (device: Device) => {
|
||||
if (device.status.h2s) {
|
||||
return (
|
||||
<Box sx={{ marginLeft: 1 }}>
|
||||
<StatusGas device={device} gasType={"h2s"} showTimestamp={showTimestamp} />
|
||||
</Box>
|
||||
)
|
||||
} else {
|
||||
return (
|
||||
<></>
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
return columns
|
||||
}
|
||||
|
||||
|
|
@ -1000,6 +1062,8 @@ export default function Devices() {
|
|||
let hasCo = false
|
||||
let hasCo2 = false
|
||||
let hasNo2 = false
|
||||
let hasLel = false
|
||||
let hasH2S = false
|
||||
resp.data.devices.forEach(device => {
|
||||
setHasPlenums(doesDeviceHavePlenum(device))
|
||||
if (doesDeviceHavePlenum(device)) hasPlenum = true
|
||||
|
|
@ -1009,6 +1073,8 @@ export default function Devices() {
|
|||
if (doesDeviceHaveCo(device)) hasCo = true
|
||||
if (doesDeviceHaveCo2(device)) hasCo2 = true
|
||||
if (doesDeviceHaveNo2(device)) hasNo2 = true
|
||||
if (doesDeviceHaveLel(device)) hasLel = true
|
||||
if (doesDeviceHaveH2S(device)) hasH2S = true
|
||||
newDevices.push(Device.create(device))
|
||||
})
|
||||
setHasPlenums(hasPlenum)
|
||||
|
|
@ -1017,6 +1083,8 @@ export default function Devices() {
|
|||
setHasCo(hasCo)
|
||||
setHasCo2(hasCo2)
|
||||
setHasNo2(hasNo2)
|
||||
setHasLel(hasLel)
|
||||
setHasH2S(hasH2S)
|
||||
setDevices(currentRows.concat(newDevices))
|
||||
}).catch(_err => {
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue