Skip to content

Commit

Permalink
fix: output null for empty MTA (air) or MTW (water) temperature. (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
willem-syt authored Dec 23, 2024
1 parent 488011e commit 4a232c2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
4 changes: 2 additions & 2 deletions hooks/MTA.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
*/
Expand All @@ -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,
},
],
},
Expand Down
5 changes: 2 additions & 3 deletions hooks/MTW.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
*/
Expand All @@ -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,
},
],
},
Expand Down
9 changes: 9 additions & 0 deletions test/MTA.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})
9 changes: 9 additions & 0 deletions test/MTW.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})

0 comments on commit 4a232c2

Please sign in to comment.