Skip to content

Commit

Permalink
feat: add DNMS sensor and handle it in luftdaten handler (#881)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpfeil authored Aug 6, 2024
1 parent 09246ca commit 48694f3
Show file tree
Hide file tree
Showing 7 changed files with 301 additions and 103 deletions.
2 changes: 1 addition & 1 deletion .scripts/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ only_models_tests=${only_models_tests:-}
git_branch=$(git rev-parse --abbrev-ref HEAD)

function runComposeCommand() {
docker-compose -p osemapitest -f ./tests/docker-compose.yml "$@"
docker compose -p osemapitest -f ./tests/docker-compose.yml "$@"
}

function cleanup() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

module.exports = {
title: 'Schalldruckpegel',
unit: 'db (A)',
sensorType: 'DNMS',
icon: 'osem-volume-up',
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

module.exports = {
title: 'Schalldruckpegel (Max)',
unit: 'db (A)',
sensorType: 'DNMS',
icon: 'osem-volume-up',
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

module.exports = {
title: 'Schalldruckpegel (Min)',
unit: 'db (A)',
sensorType: 'DNMS',
icon: 'osem-volume-up',
};
11 changes: 8 additions & 3 deletions packages/models/src/box/sensorLayouts/sensorDefinitions/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';


const veml6070_uvintensity = require('./veml6070_uvintensity'),
tsl45315_lightintensity = require('./tsl45315_lightintensity'),
bmp280_pressure = require('./bmp280_pressure'),
Expand Down Expand Up @@ -49,7 +48,10 @@ const veml6070_uvintensity = require('./veml6070_uvintensity'),
sps30_pm4 = require('./sps30_pm4'),
sps30_pm10 = require('./sps30_pm10'),
sht3x_temperature = require('./sht3x_temperature'),
sht3x_humidity = require('./sht3x_humidity');
sht3x_humidity = require('./sht3x_humidity'),
dnms_la_eq = require('./dnms_la_eq'),
dnms_la_min = require('./dnms_la_min'),
dnms_la_max = require('./dnms_la_max');
module.exports = {
hdc1008_temperature,
hdc1080_temperature,
Expand Down Expand Up @@ -99,5 +101,8 @@ module.exports = {
sps30_pm4,
sps30_pm10,
sht3x_temperature,
sht3x_humidity
sht3x_humidity,
dnms_la_eq,
dnms_la_min,
dnms_la_max,
};
32 changes: 22 additions & 10 deletions packages/models/src/measurement/decoding/luftdatenHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,24 @@ const matchings = {
humidity: ['rel. luftfeuchte', 'luftfeuchtigkeit', 'luftfeuchte'],
pressure: ['luftdruck', 'druck'],
signal: ['stärke', 'signal'],
noise_laeq: ['schallpegel', 'geräuschpegel'],
};

const findSensorId = function findSensorId (sensors, value_type) {
// temperature, humidity and pressure values
// are named either directly or with a prefix
// separated by underscores. The last element
// should be the the desired phenomenon
let [vt_sensortype, vt_phenomenon] = value_type
.toLowerCase()
.split('_');
let [vt_sensortype, vt_phenomenon] = [];
const splitAtIndex = value_type.toLowerCase().indexOf('_');
if (splitAtIndex > 0) {
[vt_sensortype, vt_phenomenon] = [
value_type.toLowerCase().slice(0, splitAtIndex),
value_type.toLowerCase().slice(splitAtIndex + 1),
];
} else {
[vt_sensortype, vt_phenomenon] = value_type.toLowerCase().split('_');
}

// DHT11 and DHT22 sensors have no underscore prefix
if (!vt_phenomenon && ['temperature', 'humidity'].includes(vt_sensortype)) {
Expand All @@ -110,9 +118,10 @@ const findSensorId = function findSensorId (sensors, value_type) {
const title = sensor.title.toLowerCase();
const type = sensor.sensorType.toLowerCase();
if (
(title === vt_phenomenon || matchings[vt_phenomenon].includes(title) || matchings[vt_phenomenon].some(alias => title.includes(alias)))
&&
(type.startsWith(vt_sensortype))
(title === vt_phenomenon ||
matchings[vt_phenomenon].includes(title) ||
matchings[vt_phenomenon].some((alias) => title.includes(alias))) &&
type.startsWith(vt_sensortype)
) {
sensorId = sensor._id.toString();
break;
Expand All @@ -137,7 +146,6 @@ const transformLuftdatenJson = function transformLuftdatenJson (json, sensors) {
return outArray;
};


module.exports = {
decodeMessage: function (message, { sensors } = {}) {
if (!sensors) {
Expand All @@ -159,7 +167,9 @@ module.exports = {
}

if (!json.sensordatavalues) {
return Promise.reject(new Error('Invalid luftdaten json. Missing `sensordatavalues`'));
return Promise.reject(
new Error('Invalid luftdaten json. Missing `sensordatavalues`')
);
}

const transformedMeasurements = transformLuftdatenJson(json, sensors);
Expand All @@ -170,6 +180,8 @@ module.exports = {
return transformAndValidateMeasurements(transformedMeasurements);
}

return Promise.reject(new Error('Cannot decode empty message (luftdaten decoder)'));
}
return Promise.reject(
new Error('Cannot decode empty message (luftdaten decoder)')
);
},
};
Loading

0 comments on commit 48694f3

Please sign in to comment.