From 4a232c2e495677e7789a3efa4c87b04de648fce5 Mon Sep 17 00:00:00 2001 From: Willem <99329835+willem-syt@users.noreply.github.com> Date: Mon, 23 Dec 2024 17:32:22 +0100 Subject: [PATCH] fix: output null for empty MTA (air) or MTW (water) temperature. (#258) --- hooks/MTA.js | 4 ++-- hooks/MTW.js | 5 ++--- test/MTA.js | 9 +++++++++ test/MTW.js | 9 +++++++++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/hooks/MTA.js b/hooks/MTA.js index 4203042d..ba17b09b 100644 --- a/hooks/MTA.js +++ b/hooks/MTA.js @@ -27,7 +27,7 @@ const utils = require('@signalk/nmea0183-utilities') * * Field Number: * 0. Degrees - * 1. Unit of Measurement, Celcius + * 1. Unit of Measurement, Celsius * 2. Checksum * */ @@ -46,7 +46,7 @@ module.exports = function (input) { values: [ { path: 'environment.outside.temperature', - value: utils.transform(utils.float(parts[0]), 'c', 'k'), + value: parts.length > 0 && parts[0].trim().length > 0 ? utils.transform(utils.float(parts[0]), 'c', 'k') : null, }, ], }, diff --git a/hooks/MTW.js b/hooks/MTW.js index 91c93e50..21f6c1f0 100644 --- a/hooks/MTW.js +++ b/hooks/MTW.js @@ -27,7 +27,7 @@ const utils = require('@signalk/nmea0183-utilities') * * Field Number: * 0. Degrees - * 1. Unit of Measurement, Celcius + * 1. Unit of Measurement, Celsius * 2. Checksum * */ @@ -43,8 +43,7 @@ module.exports = function (input) { values: [ { path: 'environment.water.temperature', - value: utils.transform(utils.float(parts[0]), 'c', 'k'), - //returns raw value, no transformation done + value: parts.length > 0 && parts[0].trim().length > 0 ? utils.transform(utils.float(parts[0]), 'c', 'k') : null, }, ], }, diff --git a/test/MTA.js b/test/MTA.js index fa891e97..de172038 100644 --- a/test/MTA.js +++ b/test/MTA.js @@ -37,4 +37,13 @@ describe('MTA', () => { should.equal(delta, null) }) + + it('Converts empty value to null', () => { + const delta = new Parser().parse('$RAMTA,,C*08') + delta.updates[0].values.length.should.equal(1) + delta.updates[0].values[0].path.should.equal( + 'environment.outside.temperature' + ) + chai.expect(delta.updates[0].values[0].value).to.be.null + }) }) diff --git a/test/MTW.js b/test/MTW.js index 6e9ef577..36355890 100644 --- a/test/MTW.js +++ b/test/MTW.js @@ -32,4 +32,13 @@ describe('MTW', () => { ) delta.updates[0].values[0].value.should.be.closeTo(288.35, 0.005) }) + + it('Converts empty value to null', () => { + const delta = new Parser().parse('$RAMTW,,C*1E') + delta.updates[0].values.length.should.equal(1) + delta.updates[0].values[0].path.should.equal( + 'environment.water.temperature' + ) + chai.expect(delta.updates[0].values[0].value).to.be.null + }) })