Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] feature: add 127507 charger status #240

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions pgns/127507.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

function prefix(n2k) {
return `electrical.charger.${n2k.fields['Instance']}.battery.${n2k.fields['Battery Instance']}`
}

module.exports = [
{
node: n2k => prefix(n2k) + '.operatingState',
value: n2k => n2k.fields['Operating State'].toLowerCase(),
filter: n2k => typeof n2k.fields['Operating State'] === 'string'
},
{
node: n2k => prefix(n2k) + '.chargeMode',
value: n2k => n2k.fields['Charge Mode'].toLowerCase(),
filter: n2k => typeof n2k.fields['Charge Mode'] === 'string'
},
{
node: n2k => prefix(n2k) + '.chargerEnabled',
value: n2k => n2k.fields['Charger Enabled'].toLowerCase(),
filter: n2k => typeof n2k.fields['Charger Enabled'] === 'string'
},
{
node: n2k => prefix(n2k) + '.equalizationPending',
value: n2k => n2k.fields['Equalization Pending'].toLowerCase(),
filter: n2k => typeof n2k.fields['Equalization Pending'] === 'string'
},
{
allowNull: true,
value: function (n2k) {
var val = n2k.fields['Equalization Time Remaining']
var res
if (typeof val !== 'undefined') {
res = val * 60 // convert to seconds
} else {
res = null
}
return res
},
node: function (n2k) {
return prefix(n2k) + '.equalizationTimeRemaining'
}
}
]
1 change: 1 addition & 0 deletions pgns/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
127489: require('./127489.js'),
127505: require('./127505.js'),
127506: require('./127506.js'),
127507: require('./127507.js'),
127508: require('./127508.js'),
128259: require('./128259.js'),
128267: require('./128267.js'),
Expand Down
43 changes: 43 additions & 0 deletions test/127507_charger_status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
var chai = require('chai')
chai.Should()
const { expect } = chai
chai.use(require('chai-things'))
chai.use(require('@signalk/signalk-schema').chaiModule)

describe('127507 charger status', function () {
it('complete sentence converts', function () {
const pgn =
'{"canId":435295105,"prio":6,"src":129,"dst":255,"pgn":127507,"timestamp":"2021-07-30T16:48:59.722Z","input":[],"fields":{"Instance":113,"Battery Instance":0,"Operating State":"Disabled","Charge Mode":"Standalone mode","Charger Enabled":"Off"},"description":"Charger Status"}'

const delta = require('./testMapper').toDelta(JSON.parse(pgn))

findPathValue(
delta,
'electrical.charger.113.battery.0.operatingState'
).value.should.equal('disabled')
findPathValue(
delta,
'electrical.charger.113.battery.0.chargeMode'
).value.should.equal('standalone mode')
findPathValue(
delta,
'electrical.charger.113.battery.0.chargerEnabled'
).value.should.equal('off')
expect(findPathValue(
delta,
'electrical.charger.113.battery.0.equalizationTimeRemaining'
).value).to.be.null
})
})

function findPathValue(delta, path) {
const found = delta.updates[0].values.find(
(pathValue) => pathValue.path === path
)
if (!found) {
throw new Error(
`No pathValue with path ${path} in ${JSON.stringify(delta, null, 2)}`
)
}
return found
}