From 76147e38a1a51c1a6ae149cdecf3da9985f0d65c Mon Sep 17 00:00:00 2001 From: bugsounet Date: Fri, 8 Mar 2024 00:49:22 +0100 Subject: [PATCH] delete loadlibrary (not needed now... because no electron rebuild) // correct alert errors --- MMM-Pir.js | 25 +++++++++--------------- node_helper.js | 53 ++++++++------------------------------------------ 2 files changed, 17 insertions(+), 61 deletions(-) diff --git a/MMM-Pir.js b/MMM-Pir.js index 3b8730e0..d195fd0d 100644 --- a/MMM-Pir.js +++ b/MMM-Pir.js @@ -1,8 +1,8 @@ -/**************** -* MMM-Pir v1.2 * -* Bugsounet * -* 02/2024 * -*****************/ +/************* +* MMM-Pir * +* Bugsounet * +* 03/2024 * +*************/ /* global screenDisplayer, screenTouch */ @@ -88,22 +88,14 @@ 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: `

FATAL: ${payload} needed library not loaded !
Try to solve it with 'npm run rebuild' in MMM-Pir Folder

`, - timer: 0 - }); - break; - case "SCREEN_ERROR": + break case "PIR_ERROR": this.sendNotification("SHOW_ALERT", { type: "notification", @@ -111,6 +103,7 @@ Module.register("MMM-Pir", { message: `Pir Error detected: ${payload}`, timer: 15000 }); + break } }, diff --git a/node_helper.js b/node_helper.js index 60bc1ab7..c7f9ac20 100644 --- a/node_helper.js +++ b/node_helper.js @@ -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; }, @@ -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 || ""); @@ -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); - }); } });