Skip to content

Commit

Permalink
feature: support switching ignore ac in (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbender9 authored Aug 18, 2023
1 parent b0d4f22 commit fa27cf9
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 11 deletions.
27 changes: 18 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,24 @@ module.exports = function (app) {
dbusSetValue(msg.destination, msg.path, msg.value)
}

function actionHandler(context, skpath, input, dest, vpath, mqttTopic, converter, cb) {
app.debug(`setting mode ${dest} ${vpath} to ${input}`)
function actionHandler(context, skpath, input, dest, vpath, mqttTopic, converter, putPath, cb) {
let realPath = putPath ? putPath : vpath
app.debug(`setting mode ${dest} ${realPath} to ${input}`)

let value = converter ? converter(input) : input

if ( plugin.options.installType === 'mqtt' ) {
const wtopic = 'W' + mqttTopic.slice(1)
let wtopic
if ( putPath ) {
// N/985dadcb01dd/system/0/Dc/System/Power
let parts = mqttTopic.split('/')
wtopic = `W/${parts[1]}/${parts[2]}/${parts[3]}${putPath}`
} else {
wtopic = 'W' + mqttTopic.slice(1)
}
plugin.client.publish(wtopic, JSON.stringify({ value }))
} else {
dbusSetValue(dest, vpath, value)
dbusSetValue(dest, realPath, value)
}

setTimeout(() => {
Expand All @@ -199,14 +207,14 @@ module.exports = function (app) {
message: 'Did not receive change confirmation'
})
}
}, 1000)
}, 2000)

return { state: 'PENDING' }
}

function getActionHandler(m, converter) {
function getActionHandler(m, converter, putPath) {
return (context, path, value, cb) => {
return actionHandler(context, path, value, m.senderName, m.path, m.topic, converter, cb)
return actionHandler(context, path, value, m.senderName, m.path, m.topic, converter, putPath, cb)
}
}

Expand All @@ -218,10 +226,11 @@ module.exports = function (app) {
plugin.start = function (options) {
var { toDelta, getKnownPaths } =
venusToDeltas(app, options, {},
(path, m, converter) => {
(path, m, converter, confirmPath) => {
app.registerActionHandler('vessels.self',
path,
getActionHandler(m,converter))
getActionHandler(m,converter,
confirmPath))
})

pluginStarted = true
Expand Down
59 changes: 57 additions & 2 deletions venusToDeltas.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ module.exports = function (app, options, state, putRegistrar) {
path: m => {
return makePath(m, `${m.instanceName}.mode`)
},
conversion: convertMode
conversion: convertMode,
putSupport: {
}
},
{
path: m => {
Expand Down Expand Up @@ -457,8 +459,56 @@ module.exports = function (app, options, state, putRegistrar) {
{
path: m => { return `electrical.${m.venusName}.acSourceNumber` },
requiresInstance: false
},
{
path: m => {
return makePath(m, `${m.instanceName}.acin.acSource`, true)
},
conversion: convertSource,
},
{
path: m => {
return makePath(m, `${m.instanceName}.acin.acSourceNumber`, true)
},
}
],
'/Ac/ActiveIn/CurrentLimit': {
path: m => {
return makePath(m, `${m.instanceName}.acin.currentLimit`, true)
},
units: 'A',
putSupport: {
}
},
'/Ac/In/1/CurrentLimit': {
path: m => {
return makePath(m, `${m.instanceName}.acin.1.currentLimit`, true)
},
units: 'A',
putSupport: {
}
},
'/Ac/In/2/CurrentLimit': {
path: m => {
return makePath(m, `${m.instanceName}.acin.2.currentLimit`, true)
},
units: 'A',
putSupport: {
}
},
'/Ac/State/IgnoreAcIn1': {
path: m => {
return makePath(m, `${m.instanceName}.acState.ignoreAcIn1.state`, true)
},
putSupport: {
putPath: m => '/Ac/Control/IgnoreAcIn1'
}
},
'/Ac/State/AcIn1Available': {
path: m => {
return makePath(m, `${m.instanceName}.acState.acIn1Available`, true)
},
},
'/Ac/ActiveIn/L1/I': {
path: m => {
return makePath(m, `${m.instanceName}.acin.current`, true)
Expand Down Expand Up @@ -877,7 +927,12 @@ module.exports = function (app, options, state, putRegistrar) {
}

if ( mapping.putSupport && putRegistrar ) {
putRegistrar(thePath, m, mapping.putSupport.conversion)
let putPath
if ( mapping.putSupport.putPath ) {
putPath = mapping.putSupport.putPath(m)
}
putRegistrar(thePath, m, mapping.putSupport.conversion,
putPath)
}
}
if ( !options.blacklist || options.blacklist.indexOf(thePath) == -1 ) {
Expand Down

0 comments on commit fa27cf9

Please sign in to comment.