Skip to content
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
3 changes: 3 additions & 0 deletions schemas/definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@
},
"sentence": {
"type": "string"
},
"preferredSource": {
"type": "string"
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions scripts/processSchemaFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class Parser {
}
}

const skipFields = ['timestamp', '$source', 'source', '_attr', 'meta', 'pgn', 'sentence', 'value', 'values']
const skipFields = ['timestamp', '$source', 'source', '_attr', 'meta', 'pgn', 'sentence', 'value', 'values', 'preferredSource']
const embeddedFields =
!this.tree[`${path}/timestamp`] ? {} :
_.pick(subtree.properties ? _.omit(subtree.properties || {}, skipFields) : {}, (value, key) => {
Expand Down Expand Up @@ -212,7 +212,7 @@ class Parser {
*/
.then(results => {
const filenames = {}
const filter = ['/timestamp', '/$source', '/source', '/_attr', '/meta', '/pgn', '/sentence', '/value', '/values']
const filter = ['/timestamp', '/$source', '/source', '/_attr', '/meta', '/pgn', '/sentence', '/value', '/values', '/preferredSource']

results.forEach(result => {
filenames[result.name] = result.path
Expand Down
14 changes: 9 additions & 5 deletions src/fullsignalk.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,15 @@ function addValue(context, contextPath, source, timestamp, pathValue) {
valueLeaf.values[sourceId].timestamp = timestamp;
setMessage(valueLeaf.values[sourceId], source);
}
assignValueToLeaf(pathValue.value, valueLeaf);
if (pathValue.path.length != 0) {
valueLeaf['$source'] = getId(source);
valueLeaf.timestamp = timestamp;
setMessage(valueLeaf, source);
var sourceId = getId(source);
if ( !valueLeaf.preferredSource || valueLeaf.preferredSource == sourceId )
{
assignValueToLeaf(pathValue.value, valueLeaf);
if (pathValue.path.length != 0) {
valueLeaf['$source'] = getId(source);
valueLeaf.timestamp = timestamp;
setMessage(valueLeaf, source);
}
}
}

Expand Down