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

Update meta.js to allow for conditional logging (based on meta.js to become 1.0.8) #9

Open
wants to merge 8 commits 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
180 changes: 97 additions & 83 deletions ProcessingManager.js

Large diffs are not rendered by default.

33 changes: 19 additions & 14 deletions directoryHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ const variablePattern = {'pre':'$','post':''};
const RESULT = variablePattern.pre + 'Result' + variablePattern.post;
const BROWSEID = variablePattern.pre + 'NavigationIdentifier' + variablePattern.post;
const MQTT = 'mqtt';
//LOGGING SETUP AND WRAPPING
//Disable the NEEO library console warning.
const { metaMessage, LOG_TYPE } = require("./metaMessage");
console.error = console.info = console.debug = console.warn = console.trace = console.dir = console.dirxml = console.group = console.groupEnd = console.time = console.timeEnd = console.assert = console.profile = function() {};
function metaLog(message) {
let initMessage = { component:'directoryHelper', type:LOG_TYPE.INFO, content:'', deviceId: null };
let myMessage = {...initMessage, ...message}
return metaMessage (myMessage);
}

class directoryHelper {
constructor(deviceId, dirname, controller) {
Expand Down Expand Up @@ -53,7 +62,7 @@ class directoryHelper {
//Take the good feeder:
//Take the good commandset:
let PastQueryValue = params.browseIdentifier.split("$PastQueryValue=")[1];
console.log('PastQueryValue' + JSON.stringify(PastQueryValue))
metaLog({type:LOG_TYPE.VERBOSE, content:'PastQueryValue' + JSON.stringify(PastQueryValue), deviceId:deviceId});
params.browseIdentifier = params.browseIdentifier.split("$PastQueryValue=")[0];
let commandSetIndex = params.browseIdentifier.split("$CommandSet=")[1];
params.browseIdentifier = params.browseIdentifier.split("$CommandSet=")[0];
Expand All @@ -63,7 +72,7 @@ class directoryHelper {
else if (params.history != undefined && params.history.length>0 && params.offset==0 && self.previousOffset == 0) {//case where we browse backward
self.currentFeederIndex = self.browseHistory[params.history.length];
if (self.currentFeederIndex == undefined) {self.currentFeederIndex = 0;}
console.log('current feeder' + self.currentFeederIndex)
metaLog({type:LOG_TYPE.VERBOSE, content:'current feeder' + self.currentFeederIndex, deviceId:deviceId});
}
else if ( params.offset != undefined && params.offset>0) {
self.previousOffset = params.offset;
Expand All @@ -89,17 +98,13 @@ class directoryHelper {
};

this.fetchCurrentList = function (deviceId, allconfigs, params) {
console.log("params: " + JSON.stringify(params));
console.log("browseIdentifier: " + params.browseIdentifier);
console.log("actionIdentifier: " + params.actionIdentifier);
console.log("current feeder: " + self.currentFeederIndex);
metaLog({type:LOG_TYPE.VERBOSE, content:"params: " + JSON.stringify(params) + " - browseIdentifier: " + params.browseIdentifier + " - actionIdentifier: " + params.actionIdentifier + " - current feeder: " + self.currentFeederIndex, deviceId:deviceId});
let cacheList = [];
return new Promise(function (resolve, reject) {

// self.currentCommandResult = [];//initialise as new commands will be done now.

self.fillTheList(deviceId, cacheList, allconfigs, params, 0, 0).then((cacheList) => {//cacheList, allconfigs, params, indentCommand
//console.log(cacheList);
//Feed the neeo list
let neeoList;
neeoList = neeoapi.buildBrowseList({
Expand Down Expand Up @@ -159,7 +164,8 @@ class directoryHelper {
let commandSet = allconfigs.commandset[indentCommand];
let processedCommand = self.controller.assignTo(BROWSEID, commandSet.command, params.browseIdentifier);
processedCommand = self.controller.vault.readVariables(processedCommand, deviceId);
console.log('Final processed Command:' + processedCommand);
metaLog({type:LOG_TYPE.VERBOSE, content:'Final processed Command:', deviceId:deviceId});
metaLog({type:LOG_TYPE.VERBOSE, content:processedCommand, deviceId:deviceId});
self.controller.commandProcessor(processedCommand, commandSet.type, deviceId)
.then((result) => {
rName = self.controller.vault.readVariables(commandSet.itemname, deviceId); //ensure that the item name chain has the variable interpreted (except $Result)
Expand Down Expand Up @@ -194,8 +200,8 @@ class directoryHelper {

})
.catch(function (err) {
console.log("Fetching error: ");
console.log(err);
metaLog({type:LOG_TYPE.ERROR, content:'Fetching Error', deviceId:deviceId});
metaLog({type:LOG_TYPE.ERROR, content:err, deviceId:deviceId});
});
}
else {
Expand Down Expand Up @@ -250,18 +256,17 @@ class directoryHelper {
while (processedCommand != processedCommand.replace("$ListIndex", ListIndex)) { // Manage Index values
processedCommand = processedCommand.replace("$ListIndex", ListIndex);
}
console.log(processedCommand);
metaLog({type:LOG_TYPE.VERBOSE, content:processedCommand, deviceId:deviceId});
self.controller.commandProcessor(processedCommand, commandSet.type, deviceId)
.then((resultC) => {
console.log(resultC);

self.controller.queryProcessor(resultC, commandSet.queryresult, commandSet.type, deviceId)
.then ((result) => {
console.log(result)
resolve(self.executeAllActions(deviceId, result, ListIndex, allCommandSet, indexCommand+1))
})
.catch ((err) => {
console.log("Error while parsing the command result.")
metaLog({type:LOG_TYPE.ERROR, content:"Error while parsing the command result.", deviceId:deviceId});
metaLog({type:LOG_TYPE.ERROR, content:err, deviceId:deviceId});
resolve(err);
})
})
Expand Down
12 changes: 11 additions & 1 deletion imageHelper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@

//LOGGING SETUP AND WRAPPING
//Disable the NEEO library console warning.
const { metaMessage, LOG_TYPE } = require("./metaMessage");
console.error = console.info = console.debug = console.warn = console.trace = console.dir = console.dirxml = console.group = console.groupEnd = console.time = console.timeEnd = console.assert = console.profile = function() {};
function metaLog(message) {
let initMessage = { component:'imageHelper', type:LOG_TYPE.INFO, content:'', deviceId: null };
let myMessage = {...initMessage, ...message}
return metaMessage (myMessage);
}

class imageHelper {
constructor(deviceId, name, variableListened, controller) {
this.name = name;
Expand All @@ -18,7 +28,7 @@ class imageHelper {
if (self.value != theValue) {
self.value = theValue;
self.controller.sendComponentUpdate({ uniqueDeviceId: deviceId, component: self.name, value: self.value})
.catch((err) => { console.log("Image Update Error : " + deviceId + " / " + err); });
.catch((err) => { metaLog({type:LOG_TYPE.ERROR, content:err, deviceId:deviceId})});
}
resolve();
});
Expand Down
15 changes: 12 additions & 3 deletions labelHelper.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
//LOGGING SETUP AND WRAPPING
//Disable the NEEO library console warning.
const { metaMessage, LOG_TYPE } = require("./metaMessage");
console.error = console.info = console.debug = console.warn = console.trace = console.dir = console.dirxml = console.group = console.groupEnd = console.time = console.timeEnd = console.assert = console.profile = function() {};
function metaLog(message) {
let initMessage = { component:'labelHelper', type:LOG_TYPE.INFO, content:'', deviceId: null };
let myMessage = {...initMessage, ...message}
return metaMessage (myMessage);
}

class labelHelper {
constructor(deviceId, name, variableListened, controller, actionVariableListened) {
Expand All @@ -18,10 +27,10 @@ class labelHelper {
if (self.actionValue != theValue) {
self.actionValue = theValue;
self.controller.sendComponentUpdate({ uniqueDeviceId: deviceId, component: self.name, value: theValue })
.catch((err) => {console.log("Label Update Action Error : " + deviceId + " / " + err) });
.catch((err) => {metaLog({type:LOG_TYPE.ERROR, content:err, deviceId:deviceId})});
setTimeout(() => {
self.controller.sendComponentUpdate({ uniqueDeviceId: deviceId, component: self.name, value: self.value })
.catch((err) => {console.log("Label Update Action Error : " + deviceId + " / " + err); });
.catch((err) => {metaLog({type:LOG_TYPE.ERROR, content:err, deviceId:deviceId})});
}, 2000)
}
resolve();
Expand All @@ -33,7 +42,7 @@ class labelHelper {
if (self.value != theValue) {
self.value = theValue;
self.controller.sendComponentUpdate({ uniqueDeviceId: deviceId, component: self.name, value: theValue })
.catch((err) => {console.log("Label Update Error : " + deviceId + " / " + err) });
.catch((err) => {metaLog({type:LOG_TYPE.ERROR, content:err, deviceId:deviceId})});
}
resolve();
});
Expand Down
Loading