Improve logging across all js files

- Based on "winston" logging library
- Removed no longer needed lodash
- Locked npm dependencies to most recent major versions to avoid installs breaking due to node module updates
This commit is contained in:
Victor Hagelbäck 2021-01-21 21:31:37 +01:00
parent ba27dd6d18
commit 4176cfb714
9 changed files with 434 additions and 214 deletions

View file

@ -1,13 +1,18 @@
const api = require('./api');
const mqtt = require('./mqtt');
const fs = require('fs');
const Logger = require('./Logger');
const PlejdService = require('./ble.bluez');
const SceneManager = require('./scene.manager');
const logger = Logger.getLogger("plejd-main");
const version = "0.4.8";
async function main() {
console.log('starting Plejd add-on v. ' + version);
logger.info(`Starting Plejd add-on v. ${version}`);
const rawData = fs.readFileSync('/data/plejd.json');
const config = JSON.parse(rawData);
@ -28,7 +33,7 @@ async function main() {
const devices = plejdApi.getDevices();
client.on('connected', () => {
console.log('plejd-mqtt: connected to mqtt.');
logger.verbose('connected to mqtt.');
client.discover(devices);
});
@ -38,7 +43,7 @@ async function main() {
const sceneManager = new SceneManager(plejdApi.site, devices);
const plejd = new PlejdService(cryptoKey, devices, sceneManager, config.connectionTimeout, config.writeQueueWaitTime, true);
plejd.on('connectFailed', () => {
console.log('plejd-ble: were unable to connect, will retry connection in 10 seconds.');
logger.verbose('Were unable to connect, will retry connection in 10 seconds.');
setTimeout(() => {
plejd.init();
}, 10000);
@ -47,7 +52,7 @@ async function main() {
plejd.init();
plejd.on('authenticated', () => {
console.log('plejd: connected via bluetooth.');
logger.verbose('plejd: connected via bluetooth.');
});
// subscribe to changes from Plejd
@ -97,16 +102,6 @@ async function main() {
plejd.turnOff(deviceId, commandObj);
}
});
client.on('settingsChanged', (settings) => {
if (settings.module === 'mqtt') {
client.updateSettings(settings);
} else if (settings.module === 'ble') {
plejd.updateSettings(settings);
} else if (settings.module === 'api') {
plejdApi.updateSettings(settings);
}
});
});
});
});