Merge pull request #34 from icanos/dev

added error handling for writing to Plejd
This commit is contained in:
Marcus Westin 2020-01-14 19:11:08 +01:00 committed by GitHub
commit f38c7ebce9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 7 deletions

View file

@ -315,6 +315,7 @@ class PlejdService extends EventEmitter {
return false; return false;
} }
try {
const encryptedData = this._encryptDecrypt(this.cryptoKey, this.deviceAddress, data); const encryptedData = this._encryptDecrypt(this.cryptoKey, this.deviceAddress, data);
this.characteristics.data.write(encryptedData, false); this.characteristics.data.write(encryptedData, false);
@ -323,6 +324,15 @@ class PlejdService extends EventEmitter {
this.characteristics.data.write(this._encryptDecrypt(this.cryptoKey, this.deviceAddress, writeData), false); 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();
}
}
onAuthenticated() { onAuthenticated() {
// Start ping // Start ping

View file

@ -1,6 +1,6 @@
{ {
"name": "Plejd", "name": "Plejd",
"version": "0.2.3", "version": "0.2.4",
"slug": "plejd", "slug": "plejd",
"description": "Adds support for the Swedish home automation devices from Plejd.", "description": "Adds support for the Swedish home automation devices from Plejd.",
"url": "https://github.com/icanos/hassio-plejd/", "url": "https://github.com/icanos/hassio-plejd/",

View file

@ -3,7 +3,7 @@ const mqtt = require('./mqtt');
const fs = require('fs'); const fs = require('fs');
const PlejdService = require('./ble'); const PlejdService = require('./ble');
const version = "0.2.3"; const version = "0.2.4";
async function main() { async function main() {
console.log('starting Plejd add-on v. ' + version); console.log('starting Plejd add-on v. ' + version);