Skip to content

Commit

Permalink
chore: cleanup tempermappings with index
Browse files Browse the repository at this point in the history
  • Loading branch information
sbender9 committed Jul 20, 2023
1 parent 39105b0 commit b30028f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
14 changes: 11 additions & 3 deletions lowrance/65285.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ module.exports = [
source: 'Actual Temperature',
node: function (n2k) {
var temperatureMapping =
temperatureMappings[n2k.fields['Temperature Source']]
if (temperatureMapping && temperatureMapping.path) {
return temperatureMapping.path
temperatureMappings[n2k.fields['Temperature Source']]

if ( temperatureMappings ) {
if (temperatureMapping.pathWithIndex) {
return temperatureMapping.pathWithIndex.replace(
'<index>',
'default'
)
} else if (temperatureMapping.path) {
return temperatureMapping.path
}
}
},
instance: function (n2k) {
Expand Down
14 changes: 11 additions & 3 deletions pgns/130311.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ module.exports = [
{
node: function (n2k) {
var temperatureMapping =
temperatureMappings[n2k.fields['Temperature Source']]
if (temperatureMapping && temperatureMapping.path) {
return temperatureMapping.path
temperatureMappings[n2k.fields['Temperature Source']]

if (temperatureMapping) {
if (temperatureMapping.pathWithIndex) {
return temperatureMapping.pathWithIndex.replace(
'<index>',
'default'
)
} else if (temperatureMapping.path) {
return temperatureMapping.path
}
}
},
source: 'Temperature'
Expand Down
3 changes: 0 additions & 3 deletions temperatureMappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ module.exports = {
path: 'environment.inside.mainCabin.temperature'
},
'Live Well Temperature': {
path: 'tanks.liveWell.default.temperature',
pathWithIndex: 'tanks.liveWell.<index>.temperature'
},
'Bait Well Temperature': {
path: 'tanks.baitWell.default.temperature',
pathWithIndex: 'tanks.baitWell.<index>.temperature'
},
'Refrigeration Temperature': {
Expand Down Expand Up @@ -66,7 +64,6 @@ module.exports = {
path: 'environment.inside.freezer.temperature'
},
'Exhaust Gas Temperature': {
path: 'propulsion.0.exhaustTemperature',
pathWithIndex: 'propulsion.<index>.exhaustTemperature'
}
}
7 changes: 6 additions & 1 deletion test/13031_temperature.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ describe('Temperature: ', function () {
'urn:mrn:imo:mmsi:230099999'
)
_.forOwn(temperatureMappings, function (mapping, key) {

let path = mapping.pathWithIndex ?
mapping.pathWithIndex.replace('<index>','0')
: mapping.path

var delta = {
context: 'vessels.urn:mrn:imo:mmsi:230099999',
updates: [
Expand All @@ -70,7 +75,7 @@ describe('Temperature: ', function () {
timestamp: '2016-10-18T15:52:48.152Z',
values: [
{
path: mapping.path,
path,
value: 0
}
]
Expand Down

0 comments on commit b30028f

Please sign in to comment.