Skip to content

Commit 24764f9

Browse files
committed
fix all luftdaten.info tests
1 parent 3d10a03 commit 24764f9

4 files changed

Lines changed: 30 additions & 26 deletions

File tree

packages/models/src/device/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ const saveMeasurements = async function saveMeasurements (device, measurements)
254254
return Promise.reject(new Error('Array expected'));
255255
}
256256

257-
const sensorIds = this.sensorIds(),
258-
lastMeasurements = {};
257+
const sensorIds = device.sensors.map(sensor => sensor.id),
258+
lastMeasurements = {};
259259

260260
// TODO: refactor
261261
// find new lastMeasurements

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ const findSensorId = function findSensorId (sensors, value_type) {
123123
matchings[vt_phenomenon].some((alias) => title.includes(alias))) &&
124124
type.startsWith(vt_sensortype)
125125
) {
126-
sensorId = sensor._id.toString();
126+
sensorId = sensor.id;
127127
break;
128128
}
129129
}
@@ -135,14 +135,14 @@ const findSensorId = function findSensorId (sensors, value_type) {
135135

136136
const transformLuftdatenJson = function transformLuftdatenJson (json, sensors) {
137137
const outArray = [];
138-
138+
139139
for (const sdv of json.sensordatavalues) {
140140
const sensor_id = findSensorId(sensors, sdv.value_type);
141141
if (sensor_id) {
142142
outArray.push({ sensor_id, value: sdv.value });
143143
}
144144
}
145-
145+
146146
return outArray;
147147
};
148148

packages/models/src/measurement/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ const getMeasurements = async function getMeasurements (sensorId, limit = 1) {
4040
};
4141

4242
const insertMeasurements = async function insertMeasurements (measurements) {
43-
return db.insert(measurementTable).values(measurements);
43+
const transformedMeasurements = measurements.map(({ sensor_id, ...rest }) => ({
44+
sensorId: sensor_id, // Rename sensor_id to sensorId
45+
...rest, // Keep the rest of the object properties unchanged
46+
}));
47+
return db.insert(measurementTable).values(transformedMeasurements);
4448
};
4549

4650
module.exports = {

tests/tests/010-luftdaten-test.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ describe('openSenseMap API luftdaten.info devices', function () {
3737
expect(response).to.have.header('content-type', 'application/json; charset=utf-8');
3838
expect(response).to.have.json('sensors', function (sensors) {
3939
expect(sensors.some(function (sensor) {
40-
return sensor.sensorType === 'DHT11' && sensor.title === 'Temperatur';
40+
return sensor.sensor_type === 'DHT11' && sensor.title === 'Temperatur';
4141
})).to.be.true;
4242
expect(sensors.some(function (sensor) {
43-
return sensor.sensorType === 'DHT11' && sensor.title === 'rel. Luftfeuchte';
43+
return sensor.sensor_type === 'DHT11' && sensor.title === 'rel. Luftfeuchte';
4444
})).to.be.true;
4545
});
4646

@@ -66,10 +66,10 @@ describe('openSenseMap API luftdaten.info devices', function () {
6666
expect(response).to.have.header('content-type', 'application/json; charset=utf-8');
6767
expect(response).to.have.json('sensors', function (sensors) {
6868
expect(sensors.some(function (sensor) {
69-
return sensor.sensorType === 'DHT22' && sensor.title === 'Temperatur';
69+
return sensor.sensor_type === 'DHT22' && sensor.title === 'Temperatur';
7070
})).to.be.true;
7171
expect(sensors.some(function (sensor) {
72-
return sensor.sensorType === 'DHT22' && sensor.title === 'rel. Luftfeuchte';
72+
return sensor.sensor_type === 'DHT22' && sensor.title === 'rel. Luftfeuchte';
7373
})).to.be.true;
7474
});
7575

@@ -95,10 +95,10 @@ describe('openSenseMap API luftdaten.info devices', function () {
9595
expect(response).to.have.header('content-type', 'application/json; charset=utf-8');
9696
expect(response).to.have.json('sensors', function (sensors) {
9797
expect(sensors.some(function (sensor) {
98-
return sensor.sensorType === 'BMP180' && sensor.title === 'Temperatur';
98+
return sensor.sensor_type === 'BMP180' && sensor.title === 'Temperatur';
9999
})).to.be.true;
100100
expect(sensors.some(function (sensor) {
101-
return sensor.sensorType === 'BMP180' && sensor.title === 'Luftdruck';
101+
return sensor.sensor_type === 'BMP180' && sensor.title === 'Luftdruck';
102102
})).to.be.true;
103103
});
104104

@@ -124,13 +124,13 @@ describe('openSenseMap API luftdaten.info devices', function () {
124124
expect(response).to.have.header('content-type', 'application/json; charset=utf-8');
125125
expect(response).to.have.json('sensors', function (sensors) {
126126
expect(sensors.some(function (sensor) {
127-
return sensor.sensorType === 'BME280' && sensor.title === 'Temperatur';
127+
return sensor.sensor_type === 'BME280' && sensor.title === 'Temperatur';
128128
})).to.be.true;
129129
expect(sensors.some(function (sensor) {
130-
return sensor.sensorType === 'BME280' && sensor.title === 'rel. Luftfeuchte';
130+
return sensor.sensor_type === 'BME280' && sensor.title === 'rel. Luftfeuchte';
131131
})).to.be.true;
132132
expect(sensors.some(function (sensor) {
133-
return sensor.sensorType === 'BME280' && sensor.title === 'Luftdruck';
133+
return sensor.sensor_type === 'BME280' && sensor.title === 'Luftdruck';
134134
})).to.be.true;
135135
});
136136

@@ -175,16 +175,16 @@ describe('openSenseMap API luftdaten.info devices', function () {
175175
expect(response).to.have.header('content-type', 'application/json; charset=utf-8');
176176
expect(response).to.have.json('sensors', function (sensors) {
177177
expect(sensors.some(function (sensor) {
178-
return sensor.sensorType === 'DHT22' && sensor.title === 'Außentemperatur';
178+
return sensor.sensor_type === 'DHT22' && sensor.title === 'Außentemperatur';
179179
})).to.be.true;
180180
expect(sensors.some(function (sensor) {
181-
return sensor.sensorType === 'DHT22' && sensor.title === 'rel. Luftfeuchte draußen';
181+
return sensor.sensor_type === 'DHT22' && sensor.title === 'rel. Luftfeuchte draußen';
182182
})).to.be.true;
183183
expect(sensors.some(function (sensor) {
184-
return sensor.sensorType === 'BMP180' && sensor.title === 'Kellertemperatur';
184+
return sensor.sensor_type === 'BMP180' && sensor.title === 'Kellertemperatur';
185185
})).to.be.true;
186186
expect(sensors.some(function (sensor) {
187-
return sensor.sensorType === 'BMP180' && sensor.title === 'Luftdruck Keller';
187+
return sensor.sensor_type === 'BMP180' && sensor.title === 'Luftdruck Keller';
188188
})).to.be.true;
189189
});
190190

@@ -345,19 +345,19 @@ describe('openSenseMap API luftdaten.info devices', function () {
345345
.then(function (response) {
346346
expect(response).to.have.json('sensors', function (sensors) {
347347
sensors.forEach(function (sensor) {
348-
if (sensor.title === 'Temperatur' && sensor.sensorType === 'DHT22') {
348+
if (sensor.title === 'Temperatur' && sensor.sensor_type === 'DHT22') {
349349
expect(sensor.lastMeasurement.value).to.equal('24.30');
350350
}
351-
if (sensor.title === 'Kellertemperatur' && sensor.sensorType === 'BMP180') {
352-
expect(sensor.lastMeasurement.value).to.equal('26.00');
351+
if (sensor.title === 'Kellertemperatur' && sensor.sensor_type === 'BMP180') {
352+
expect(sensor.lastMeasurement.value).to.equal('26');
353353
}
354-
if (sensor.title === 'rel. Luftfeuchte' && sensor.sensorType === 'DHT22') {
355-
expect(sensor.lastMeasurement.value).to.equal('63.00');
354+
if (sensor.title === 'rel. Luftfeuchte' && sensor.sensor_type === 'DHT22') {
355+
expect(sensor.lastMeasurement.value).to.equal('63');
356356
}
357-
if (sensor.title === 'Luftdruck Keller' && sensor.sensorType === 'BMP180') {
357+
if (sensor.title === 'Luftdruck Keller' && sensor.sensor_type === 'BMP180') {
358358
expect(sensor.lastMeasurement.value).to.equal('100590');
359359
}
360-
if (sensor.title === 'Wifi Signal' && sensor.sensorType === 'Wifi') {
360+
if (sensor.title === 'Wifi Signal' && sensor.sensor_type === 'Wifi') {
361361
expect(sensor.lastMeasurement.value).to.equal('-64');
362362
}
363363

0 commit comments

Comments
 (0)