From c69400054b78862f4a12dfafc4086db80fc9d5fc Mon Sep 17 00:00:00 2001 From: Grzegorz Date: Sun, 18 Aug 2024 23:14:35 +0200 Subject: [PATCH] release v2.1.1 --- CHANGELOG.md | 11 +++++++++-- index.js | 44 ++++++++++++++++++++++++++++---------------- package.json | 2 +- src/deviceata.js | 5 ++++- src/deviceatw.js | 5 ++++- src/deviceerv.js | 5 ++++- src/melcloud.js | 12 ++++++------ src/melcloudata.js | 5 +++-- src/melcloudatw.js | 5 +++-- src/melclouderv.js | 5 +++-- 10 files changed, 65 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc16ec2..381deac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - After update to this version the devices need to be added to the Home app again and the old unresponsive remove!!!- This devices will be removed from all automations and scenes!!! +### After update to v2.0.0 RESTFull and MQTT config settings need to be updated + +## [2.1.1] - (18.08.2024) + +## Changes + +- fix correct catch error +- log improvements + ## [2.1.0] - (16.08.2024) ## Changes @@ -32,8 +41,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Changes -### After update to v2.0.0 RESTFull and MQTT config settings need to be updated - - RestFul and MQTT refactor - bump dependencies - cleanup diff --git a/index.js b/index.js index adbf33a..25eca5c 100644 --- a/index.js +++ b/index.js @@ -51,7 +51,7 @@ class MelCloudPlatform { //debug config const enableDebugMode = account.enableDebugMode || false; - const debug = enableDebugMode ? log(`Account: ${accountName}, did finish launching.`) : false; + const debug = enableDebugMode ? log.info(`Account: ${accountName}, did finish launching.`) : false; //remove sensitive data const debugData = { @@ -62,7 +62,7 @@ class MelCloudPlatform { passwd: 'removed' } }; - const debug1 = enableDebugMode ? log(`Account: ${accountName}, Config: ${JSON.stringify(debugData, null, 2)}`) : false; + const debug1 = enableDebugMode ? log.info(`Account: ${accountName}, Config: ${JSON.stringify(debugData, null, 2)}`) : false; //set refresh interval const accountInfoFile = `${prefDir}/${accountName}_Account`; @@ -92,16 +92,19 @@ class MelCloudPlatform { //publish device api.publishExternalAccessories(CONSTANTS.PluginName, [accessory]); - const debug = enableDebugMode ? log(`${accountName}, ${deviceTypeText} ${deviceName}, published as external accessory.`) : false; + log.success(`${accountName}, ${deviceTypeText} ${deviceName}, published as external accessory.`); }) .on('devInfo', (devInfo) => { - log(devInfo); + log.info(devInfo); }) .on('message', (message) => { - log(`${deviceTypeText}, ${deviceName}, ${message}`); + log.info(`${deviceTypeText}, ${deviceName}, ${message}`); }) .on('debug', (debug) => { - log(`${deviceTypeText}, ${deviceName}, debug: ${debug}`); + log.info(`${deviceTypeText}, ${deviceName}, debug: ${debug}`); + }) + .on('warn', (warn) => { + log.warn(`${deviceTypeText}, ${deviceName}, ${warn}`); }) .on('error', (error) => { log.error(`${deviceTypeText}, ${deviceName}, ${error}`); @@ -118,16 +121,19 @@ class MelCloudPlatform { //publish device api.publishExternalAccessories(CONSTANTS.PluginName, [accessory]); - const debug = enableDebugMode ? log(`${accountName}, ${deviceTypeText} ${deviceName}, published as external accessory.`) : false; + log.success(`${accountName}, ${deviceTypeText} ${deviceName}, published as external accessory.`); }) .on('devInfo', (devInfo) => { - log(devInfo); + log.info(devInfo); }) .on('message', (message) => { - log(`${deviceTypeText}, ${deviceName}, ${message}`); + log.info(`${deviceTypeText}, ${deviceName}, ${message}`); }) .on('debug', (debug) => { - log(`${deviceTypeText}, ${deviceName}, debug: ${debug}`); + log.info(`${deviceTypeText}, ${deviceName}, debug: ${debug}`); + }) + .on('warn', (warn) => { + log.warn(`${deviceTypeText}, ${deviceName}, ${warn}`); }) .on('error', (error) => { log.error(`${deviceTypeText}, ${deviceName}, ${error}`); @@ -144,16 +150,19 @@ class MelCloudPlatform { //publish device api.publishExternalAccessories(CONSTANTS.PluginName, [accessory]); - const debug = enableDebugMode ? log(`${accountName}, ${deviceTypeText} ${deviceName}, published as external accessory.`) : false; + log.success(`${accountName}, ${deviceTypeText} ${deviceName}, published as external accessory.`); }) .on('devInfo', (devInfo) => { - log(devInfo); + log.info(devInfo); }) .on('message', (message) => { - log(`${deviceTypeText}, ${deviceName}, ${message}`); + log.info(`${deviceTypeText}, ${deviceName}, ${message}`); }) .on('debug', (debug) => { - log(`${deviceTypeText}, ${deviceName}, debug: ${debug}`); + log.info(`${deviceTypeText}, ${deviceName}, debug: ${debug}`); + }) + .on('warn', (warn) => { + log.warn(`${deviceTypeText}, ${deviceName}, ${warn}`); }) .on('error', (error) => { log.error(`${deviceTypeText}, ${deviceName}, ${error}`); @@ -165,10 +174,13 @@ class MelCloudPlatform { } }) .on('message', (message) => { - log(`Account ${accountName}, ${message}`); + log.info(`Account ${accountName}, ${message}`); }) .on('debug', (debug) => { - log(`Account ${accountName}, debug: ${debug}`); + log.info(`Account ${accountName}, debug: ${debug}`); + }) + .on('warn', (warn) => { + log.warn(`${deviceTypeText}, ${deviceName}, ${warn}`); }) .on('error', async (error) => { log.error(`Account ${accountName}, ${error}, check again in: ${refreshInterval / 1000}s.`); diff --git a/package.json b/package.json index f26afef..2f441ed 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "displayName": "MELCloud Control", "name": "homebridge-melcloud-control", - "version": "2.0.3", + "version": "2.1.1", "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.", "license": "MIT", "author": "grzegorz914", diff --git a/src/deviceata.js b/src/deviceata.js index 34e54f9..e9b006f 100644 --- a/src/deviceata.js +++ b/src/deviceata.js @@ -573,6 +573,9 @@ class DeviceAta extends EventEmitter { .on('debug', (debug) => { this.emit('debug', debug); }) + .on('warn', (warn) => { + this.emit('warn', warn); + }) .on('error', (error) => { this.emit('error', error); }); @@ -1234,7 +1237,7 @@ class DeviceAta extends EventEmitter { return accessory; } catch (error) { - this.emit('error', error); + throw new Error(error); }; }; }; diff --git a/src/deviceatw.js b/src/deviceatw.js index d14837c..f45648e 100644 --- a/src/deviceatw.js +++ b/src/deviceatw.js @@ -773,6 +773,9 @@ class DeviceAtw extends EventEmitter { .on('debug', (debug) => { this.emit('debug', debug); }) + .on('warn', (warn) => { + this.emit('warn', warn); + }) .on('error', (error) => { this.emit('error', error); }); @@ -1710,7 +1713,7 @@ class DeviceAtw extends EventEmitter { return accessory; } catch (error) { - this.emit('error', error); + throw new Error(error); }; }; }; diff --git a/src/deviceerv.js b/src/deviceerv.js index 8adf92f..7c9fc53 100644 --- a/src/deviceerv.js +++ b/src/deviceerv.js @@ -539,6 +539,9 @@ class DeviceErv extends EventEmitter { .on('debug', (debug) => { this.emit('debug', debug); }) + .on('warn', (warn) => { + this.emit('warn', warn); + }) .on('error', (error) => { this.emit('error', error); }); @@ -1150,7 +1153,7 @@ class DeviceErv extends EventEmitter { return accessory; } catch (error) { - this.emit('error', error); + throw new Error(error); }; }; }; diff --git a/src/melcloud.js b/src/melcloud.js index 1322e5d..2de16ae 100644 --- a/src/melcloud.js +++ b/src/melcloud.js @@ -79,7 +79,7 @@ class MelCloud extends EventEmitter { const debug1 = this.enableDebugMode ? this.emit('debug', `MELCloud Info: ${JSON.stringify(debugData, null, 2)}`) : false; if (contextKey === undefined || contextKey === null) { - this.emit('message', `Context key: ${contextKey}, missing.`) + this.emit('warn', `Context key: ${contextKey}, missing.`) return; }; @@ -143,7 +143,7 @@ class MelCloud extends EventEmitter { const debug1 = this.enableDebugMode ? this.emit('debug', `Buildings: ${JSON.stringify(buildingsList, null, 2)}`) : false; if (!buildingsList) { - this.emit('message', `No building found.`); + this.emit('warn', `No building found.`); return; } @@ -169,7 +169,7 @@ class MelCloud extends EventEmitter { const devicesCount = devices.length; if (devicesCount === 0) { - this.emit('message', `No devices found.`); + this.emit('warn', `No devices found.`); return; } const debug3 = this.enableDebugMode ? this.emit('debug', `Found: ${devicesCount} devices.`) : false; @@ -192,7 +192,7 @@ class MelCloud extends EventEmitter { } return true; } catch (error) { - this.emit('error', `Scanning for devices error: ${error}.`); + throw new Error(`Scanning for devices error: ${error}.`); }; } @@ -202,7 +202,7 @@ class MelCloud extends EventEmitter { const debug3 = this.enableDebugMode ? this.emit('debug', `Data saved to path: ${path}.`) : false; return true; } catch (error) { - this.emit('error', `Save data to path: ${path}, error: ${error}`); + throw new Error(`Save data to path: ${path}, error: ${error}`); } } @@ -216,7 +216,7 @@ class MelCloud extends EventEmitter { await this.saveData(this.accountInfoFile, accountInfo); return true; } catch (error) { - this.emit('error', error); + throw new Error(error); }; }; }; diff --git a/src/melcloudata.js b/src/melcloudata.js index ac8dc4c..e2926fc 100644 --- a/src/melcloudata.js +++ b/src/melcloudata.js @@ -60,6 +60,7 @@ class MelCloudAta extends EventEmitter { const debug1 = debugLog ? this.emit('debug', `Device Info: ${JSON.stringify(deviceData, null, 2)}`) : false; if (!deviceData) { + this.emit('warn', `Device not data found.`); return; } @@ -369,7 +370,7 @@ class MelCloudAta extends EventEmitter { const data = savedData.length > 0 ? JSON.parse(savedData) : false; return data; } catch (error) { - this.emit('error', `Read data from path: ${path}, error: ${error}`); + throw new Error(`Read data from path: ${path}, error: ${error}`); } } @@ -414,7 +415,7 @@ class MelCloudAta extends EventEmitter { this.emit('deviceState', this.deviceData, deviceState, this.useFahrenheit); return true;; } catch (error) { - this.emit('error', error); + throw new Error(error); }; }; }; diff --git a/src/melcloudatw.js b/src/melcloudatw.js index e0dde1b..6b756da 100644 --- a/src/melcloudatw.js +++ b/src/melcloudatw.js @@ -60,6 +60,7 @@ class MelCloudAtw extends EventEmitter { const debug1 = debugLog ? this.emit('debug', `Device Info: ${JSON.stringify(deviceData, null, 2)}`) : false; if (!deviceData) { + this.emit('warn', `Device not data found.`); return; } @@ -440,7 +441,7 @@ class MelCloudAtw extends EventEmitter { const data = savedData.length > 0 ? JSON.parse(savedData) : false; return data; } catch (error) { - this.emit('error', `Read data from path: ${path}, error: ${error}`); + throw new Error(`Read data from path: ${path}, error: ${error}`); } } @@ -467,7 +468,7 @@ class MelCloudAtw extends EventEmitter { this.emit('deviceState', this.deviceData, deviceState, this.useFahrenheit); return true; } catch (error) { - this.emit('error', error); + throw new Error(error); }; }; }; diff --git a/src/melclouderv.js b/src/melclouderv.js index b913d0d..ee413d3 100644 --- a/src/melclouderv.js +++ b/src/melclouderv.js @@ -60,6 +60,7 @@ class MelCloudErv extends EventEmitter { const debug1 = debugLog ? this.emit('debug', `Device Info: ${JSON.stringify(deviceData, null, 2)}`) : false; if (!deviceData) { + this.emit('warn', `Device not data found.`); return; } @@ -357,7 +358,7 @@ class MelCloudErv extends EventEmitter { const data = savedData.length > 0 ? JSON.parse(savedData) : false; return data;; } catch (error) { - this.emit('error', `Read data from path: ${path}, error: ${error}`); + throw new Error(`Read data from path: ${path}, error: ${error}`); } } @@ -378,7 +379,7 @@ class MelCloudErv extends EventEmitter { this.emit('deviceState', this.deviceData, deviceState, this.useFahrenheit); return true; } catch (error) { - this.emit('error', error); + throw new Error(error); }; }; };