Skip to content

Commit f47a9fa

Browse files
authored
Fix broken sensors with undefined values (#691)
1 parent cf1e9ca commit f47a9fa

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

packages/models/src/box/box.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,9 @@ boxSchema.methods.saveMeasurement = function saveMeasurement (measurement) {
497497
boxSchema.methods.sensorIds = function sensorIds () {
498498
const sensorIds = [];
499499
for (let i = this.sensors.length - 1; i >= 0; i--) {
500-
sensorIds.push(this.sensors[i]._id.toString());
500+
if (this.sensors[i]._id) {
501+
sensorIds.push(this.sensors[i]._id.toString());
502+
}
501503
}
502504

503505
return sensorIds;

packages/models/src/measurement/decoding/luftdatenHandler.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,17 @@ const findSensorId = function findSensorId (sensors, value_type) {
106106
let sensorId;
107107

108108
for (const sensor of sensors) {
109-
const title = sensor.title.toLowerCase();
110-
const type = sensor.sensorType.toLowerCase();
111-
if (
112-
(title === vt_phenomenon || matchings[vt_phenomenon].includes(title) || matchings[vt_phenomenon].some(alias => title.includes(alias)))
113-
&&
114-
(type.startsWith(vt_sensortype))
115-
) {
116-
sensorId = sensor._id.toString();
117-
break;
109+
if (sensor.title && sensor.sensorType) {
110+
const title = sensor.title.toLowerCase();
111+
const type = sensor.sensorType.toLowerCase();
112+
if (
113+
(title === vt_phenomenon || matchings[vt_phenomenon].includes(title) || matchings[vt_phenomenon].some(alias => title.includes(alias)))
114+
&&
115+
(type.startsWith(vt_sensortype))
116+
) {
117+
sensorId = sensor._id.toString();
118+
break;
119+
}
118120
}
119121
}
120122

0 commit comments

Comments
 (0)