From dfdc7b4927bbab8ee51aef4fc29603a8d3aad29b Mon Sep 17 00:00:00 2001 From: icanos Date: Tue, 14 Jan 2020 18:08:02 +0000 Subject: [PATCH 1/2] added catch for write error unknown peripheral --- plejd/ble.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/plejd/ble.js b/plejd/ble.js index 5f101b1..31cff5b 100644 --- a/plejd/ble.js +++ b/plejd/ble.js @@ -315,12 +315,22 @@ class PlejdService extends EventEmitter { return false; } - const encryptedData = this._encryptDecrypt(this.cryptoKey, this.deviceAddress, data); - this.characteristics.data.write(encryptedData, false); + try { + const encryptedData = this._encryptDecrypt(this.cryptoKey, this.deviceAddress, data); + this.characteristics.data.write(encryptedData, false); - let writeData; - while ((writeData = this.writeQueue.shift()) !== undefined) { - this.characteristics.data.write(this._encryptDecrypt(this.cryptoKey, this.deviceAddress, writeData), false); + let writeData; + while ((writeData = this.writeQueue.shift()) !== undefined) { + this.characteristics.data.write(this._encryptDecrypt(this.cryptoKey, this.deviceAddress, writeData), false); + } + } + catch (error) { + console.log('error: writing to plejd: ' + error); + console.log('will reconnect and try again.'); + this.writeQueue.push(data); + + this.disconnect(); + this.connect(); } } From a1402c466cd90b7bc89139b279407cf357c7ac99 Mon Sep 17 00:00:00 2001 From: icanos Date: Tue, 14 Jan 2020 18:08:28 +0000 Subject: [PATCH 2/2] new version --- plejd/config.json | 2 +- plejd/main.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plejd/config.json b/plejd/config.json index 5e4d574..cfa68fe 100644 --- a/plejd/config.json +++ b/plejd/config.json @@ -1,6 +1,6 @@ { "name": "Plejd", - "version": "0.2.3", + "version": "0.2.4", "slug": "plejd", "description": "Adds support for the Swedish home automation devices from Plejd.", "url": "https://github.com/icanos/hassio-plejd/", diff --git a/plejd/main.js b/plejd/main.js index 4e6fafd..919b794 100644 --- a/plejd/main.js +++ b/plejd/main.js @@ -3,7 +3,7 @@ const mqtt = require('./mqtt'); const fs = require('fs'); const PlejdService = require('./ble'); -const version = "0.2.3"; +const version = "0.2.4"; async function main() { console.log('starting Plejd add-on v. ' + version);