diff --git a/plejd/ble.js b/plejd/ble.js index 31cff5b..64bc31c 100644 --- a/plejd/ble.js +++ b/plejd/ble.js @@ -147,7 +147,7 @@ class PlejdService extends EventEmitter { this._turnOff(id); return; } - + this._turnOn(id, currentBrightness); i++; @@ -253,17 +253,28 @@ class PlejdService extends EventEmitter { clearInterval(this.pingRef); - this.device.removeAllListeners('servicesDiscover'); - this.device.removeAllListeners('connect'); - this.device.removeAllListeners('disconnect'); - this.characteristics.auth.removeAllListeners('read'); - this.characteristics.auth.removeAllListeners('write'); - this.characteristics.data.removeAllListeners('read'); - this.characteristics.data.removeAllListeners('write'); - this.characteristics.lastData.removeAllListeners('read'); - this.characteristics.lastData.removeAllListeners('write'); - this.characteristics.ping.removeAllListeners('read'); - this.characteristics.ping.removeAllListeners('write'); + if (this.device) { + this.device.removeAllListeners('servicesDiscover'); + this.device.removeAllListeners('connect'); + this.device.removeAllListeners('disconnect'); + } + if (this.characteristics.auth) { + this.characteristics.auth.removeAllListeners('read'); + this.characteristics.auth.removeAllListeners('write'); + } + if (this.characteristics.data) { + this.characteristics.data.removeAllListeners('read'); + this.characteristics.data.removeAllListeners('write'); + } + if (this.characteristics.lastData) { + this.characteristics.lastData.removeAllListeners('read'); + this.characteristics.lastData.removeAllListeners('write'); + } + if (this.characteristics.ping) { + this.characteristics.ping.removeAllListeners('read'); + this.characteristics.ping.removeAllListeners('write'); + } + this.connectEventHooked = false; diff --git a/plejd/config.json b/plejd/config.json index cf73e06..1b1eb14 100644 --- a/plejd/config.json +++ b/plejd/config.json @@ -1,6 +1,6 @@ { "name": "Plejd", - "version": "0.2.5", + "version": "0.2.6", "slug": "plejd", "description": "Adds support for the Swedish home automation devices from Plejd.", "url": "https://github.com/icanos/hassio-plejd/", @@ -32,4 +32,4 @@ "mqttPassword": "str", "includeRoomsAsLights": "bool" } -} +} \ No newline at end of file diff --git a/plejd/main.js b/plejd/main.js index 098f869..17ca62b 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.5"; +const version = "0.2.6"; async function main() { console.log('starting Plejd add-on v. ' + version); @@ -60,7 +60,7 @@ async function main() { else if (settings.module === 'api') { plejdApi.updateSettings(settings); } - }); + }); }); });