Skip to content

Commit

Permalink
delete loadlibrary (not needed now... because no electron rebuild) //…
Browse files Browse the repository at this point in the history
… correct alert errors
  • Loading branch information
bugsounet committed Mar 7, 2024
1 parent 11640c4 commit 76147e3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 61 deletions.
25 changes: 9 additions & 16 deletions MMM-Pir.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/****************
* MMM-Pir v1.2 *
* Bugsounet *
* 02/2024 *
*****************/
/*************
* MMM-Pir *
* Bugsounet *
* 03/2024 *
*************/

/* global screenDisplayer, screenTouch */

Expand Down Expand Up @@ -88,29 +88,22 @@ Module.register("MMM-Pir", {
if (payload) this.sendNotification("USER_PRESENCE", true);
else this.sendNotification("USER_PRESENCE", false);
break;
case "WARNING":
case "SCREEN_ERROR":
this.sendNotification("SHOW_ALERT", {
type: "notification",
title: "MMM-Pir",
message: `Warning: Library not loaded: ${payload.library}`,
message: `Screen Error detected: ${payload}`,
timer: 15000
});
break;
case "FatalError":
this.sendNotification("SHOW_ALERT", {
title: "MMM-Pir",
message: `<p>FATAL: ${payload} needed library not loaded !<br>Try to solve it with 'npm run rebuild' in MMM-Pir Folder</p>`,
timer: 0
});
break;
case "SCREEN_ERROR":
break
case "PIR_ERROR":
this.sendNotification("SHOW_ALERT", {
type: "notification",
title: "MMM-Pir",
message: `Pir Error detected: ${payload}`,
timer: 15000
});
break
}
},

Expand Down
53 changes: 8 additions & 45 deletions node_helper.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/*******************************
* node_helper for MMM-Pir v1.2 *
* BuGsounet *
********************************/
/**************************
* node_helper for MMM-Pir *
* BuGsounet *
***************************/

var log = (...args) => { /* do nothing */ };
const LibScreen = require("./components/screenLib.js");
const LibPir = require("./components/pirLib.js");
const NodeHelper = require("node_helper");

module.exports = NodeHelper.create({
start () {
this.lib = { error: 0 };
this.pir = null;
this.screen = null;
},
Expand Down Expand Up @@ -43,13 +44,6 @@ module.exports = NodeHelper.create({
async parse () {
if (this.config.debug) log = (...args) => { console.log("[MMM-Pir]", ...args); };
console.log("[MMM-Pir] Version:", require("./package.json").version, "rev:", require("./package.json").rev);
let bugsounet = await this.libraries();
if (bugsounet) {
console.error("[MMM-Pir] [LIBRARY] Warning:", bugsounet, "needed library not loaded !");
console.error("[MMM-Pir] [LIBRARY] Try to solve it with `npm run rebuild` in MMM-Pir directory");
this.sendSocketNotification("FatalError", bugsounet);
return;
}
var callbacks = {
screen: (noti, params) => {
log("[CALLBACK] Screen:", noti, params || "");
Expand Down Expand Up @@ -77,42 +71,11 @@ module.exports = NodeHelper.create({
wrandrForceMode: this.config.wrandrForceMode
};

this.pir = new this.lib.Pir(pirConfig, callbacks.pir);
this.pir = new LibPir(pirConfig, callbacks.pir);
this.pir.start();
this.screen = new this.lib.Screen(screenConfig, callbacks.screen);
this.screen = new LibScreen(screenConfig, callbacks.screen);
this.screen.activate();
console.log("[MMM-Pir] Started!");
this.sendSocketNotification("INITIALIZED");
},

/** Load sensible library without black screen **/
libraries () {
let libraries = [
// { "library to load" : "store library name" }
{ "./components/pirLib.js": "Pir" },
{ "./components/screenLib.js": "Screen" }
];
let errors = 0;
return new Promise((resolve) => {
libraries.forEach((library) => {
for (const [name, configValues] of Object.entries(library)) {
let libraryToLoad = name;
let libraryName = configValues;
try {
if (!this.lib[libraryName]) {
this.lib[libraryName] = require(libraryToLoad);
log(`[DATABASE] Loaded: ${libraryToLoad} --> this.lib.${libraryName}`);
}
} catch (e) {
console.error(`[MMM-Pir] [DATABASE] ${libraryToLoad} Loading error!`, e.message);
this.sendSocketNotification("WARNING", { library: libraryToLoad });
errors++;
this.lib.error = errors;
}
}
});
if (!errors) console.log("[MMM-Pir] [DATABASE] All libraries loaded!");
resolve(errors);
});
}
});

0 comments on commit 76147e3

Please sign in to comment.