From 90b5ecd454ba737d572035426f45de4a5394c7d6 Mon Sep 17 00:00:00 2001 From: Marcus Westin Date: Thu, 16 Jan 2020 20:12:15 +0100 Subject: [PATCH 1/6] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 0c2c3ae..acc3233 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,9 @@ Check this out for more information on how you can get your Plejd lights control https://www.home-assistant.io/integrations/homekit/ ## Changelog +*v 0.2.8*: +* FIX: Reset characteristic state on disconnect + *v 0.2.7*: * FIX: Added exception handling to unsubscribing lastData characteristic if already disconnected From eead389056b3db040fee62caefbc55157ca6343b Mon Sep 17 00:00:00 2001 From: Marcus Westin Date: Thu, 16 Jan 2020 20:12:59 +0100 Subject: [PATCH 2/6] Update README.md --- plejd/README.md | 54 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/plejd/README.md b/plejd/README.md index ea4a8a3..acc3233 100644 --- a/plejd/README.md +++ b/plejd/README.md @@ -9,6 +9,9 @@ Thanks to [ha-plejd](https://github.com/klali/ha-plejd) for inspiration. Disclaimer: I am in no way affiliated with Plejd and am solely doing this as a hobby project. +**Did you like this? Consider helping me continue the development:** +[Buy me a coffee](https://www.buymeacoffee.com/w1ANTUb) + ## Getting started To get started, make sure that the following requirements are met: @@ -33,7 +36,7 @@ The add-on has been tested on the following platforms: Browse to your Home Assistant installation in a web browser and click on `Hass.io` in the navigation bar to the left. * Open the Home Assistant web console and click `Hass.io` in the menu on the left side. * Click on `Add-on Store` in the top navigation bar of that page. -* Paste the URL to this repo https://github.com/icanos/hassio-plejd/ in the `Add new repository by URL` field and hit `Add`. +* Paste the URL to this repo https://github.com/icanos/hassio-plejd.git in the `Add new repository by URL` field and hit `Add`. * Scroll down and you should find a Plejd add-on that can be installed. Open that and install. * Enjoy! @@ -48,11 +51,19 @@ Browse your Hass.io installation using a tool that allows you to manage files, f * A new Local Add-on should appear named Plejd. Open that and install. * Enjoy! +### NOTE +When starting the add-on, the log displays this message: +``` +parse error: Expected string key before ':' at line 1, column 4 +[08:56:24] ERROR: Unknown HTTP error occured +``` +However, the add-on still works as expected and this is something I'm looking into, but not with that much effort yet though. + ### Configuration You need to add the following to your `configuration.yaml` file: ``` mqtt: - broker: [point to your broker IP] + broker: [point to your broker IP eg. 'mqtt://localhost'] username: [username of mqtt broker] password: !secret mqtt_password discovery: true @@ -87,10 +98,43 @@ Check this out for more information on how you can get your Plejd lights control https://www.home-assistant.io/integrations/homekit/ ## Changelog -*0.1.4*: -* FIX: bug preventing add-on from building +*v 0.2.8*: +* FIX: Reset characteristic state on disconnect -*0.1.3*: +*v 0.2.7*: +* FIX: Added exception handling to unsubscribing lastData characteristic if already disconnected + +*v 0.2.6*: +* FIX: Added null check to remove listeners for characteristics + +*v 0.2.5*: +* FIX: Invalid scene id in events/scene message + +*v 0.2.4*: +* Stability improvements + +*v 0.2.3*: +* FIX: Container build error fix + +*v 0.2.2*: +* Stability improvements + +*v 0.2.1*: +* Stability improvements + +*v 0.2.0*: +* Stability improvements +* Bugfixes + +*v 0.1.1*: +* FIX: Fixed missing reference on startup, preventing add-on from starting + +*v 0.1.0*: +* NEW: Rewrote the BLE integration for more stability +* FIX: discovery wasn't always sent + +*previous*: +* FIX: bug preventing add-on from building * NEW: Added support for Plejd devices with multiple outputs (such as DIM-02) ## License From b039baea5bd7073fdf23f57e9a27e65623fdfc36 Mon Sep 17 00:00:00 2001 From: icanos Date: Sat, 18 Jan 2020 16:00:31 +0000 Subject: [PATCH 3/6] added sorted list of devices discovered --- plejd/api.js | 5 ++-- plejd/ble.js | 3 +- plejd/config.json | 2 +- plejd/main.js | 6 ++-- plejd/mqtt.js | 2 +- plejd/package-lock.json | 66 ++--------------------------------------- plejd/package.json | 2 +- 7 files changed, 15 insertions(+), 71 deletions(-) diff --git a/plejd/api.js b/plejd/api.js index 91e2e98..00997eb 100644 --- a/plejd/api.js +++ b/plejd/api.js @@ -45,7 +45,7 @@ class PlejdApi extends EventEmitter { login() { console.log('plejd-api: login()'); - console.log('logging into ' + this.siteName); + console.log('plejd-api: logging into ' + this.siteName); const self = this; const instance = axios.create({ @@ -100,7 +100,8 @@ class PlejdApi extends EventEmitter { self.site = response.data.result.find(x => x.site.title == self.siteName); self.cryptoKey = self.site.plejdMesh.cryptoKey; - callback(self.cryptoKey); + this.emit('ready', self.cryptoKey); + //callback(self.cryptoKey); }) .catch((error) => { console.log('error: unable to retrieve the crypto key. error: ' + error + ' (code: ' + error.response.status + ')'); diff --git a/plejd/ble.js b/plejd/ble.js index 81552d2..fbddafa 100644 --- a/plejd/ble.js +++ b/plejd/ble.js @@ -198,7 +198,8 @@ class PlejdService extends EventEmitter { } if (!uuid) { - this.device = Object.values(this.devices)[this.deviceIdx]; + this.sortedDevices = Object.values(this.devices).sort((a, b) => b.rssi - a.rssi); + this.device = sortedDevices[this.deviceIdx]; } else { this.device = this.devices[uuid]; diff --git a/plejd/config.json b/plejd/config.json index 7da0a74..3436864 100644 --- a/plejd/config.json +++ b/plejd/config.json @@ -1,6 +1,6 @@ { "name": "Plejd", - "version": "0.2.8", + "version": "0.2.9", "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 5aff784..e2360fe 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.8"; +const version = "0.2.9"; async function main() { console.log('starting Plejd add-on v. ' + version); @@ -15,7 +15,7 @@ async function main() { const client = new mqtt.MqttClient(config.mqttBroker, config.mqttUsername, config.mqttPassword); plejdApi.once('loggedIn', () => { - plejdApi.getCryptoKey((cryptoKey) => { + plejdApi.on('ready', (cryptoKey) => { const devices = plejdApi.getDevices(); client.on('connected', () => { @@ -62,6 +62,8 @@ async function main() { } }); }); + + plejdApi.getCryptoKey(); }); plejdApi.login(); diff --git a/plejd/mqtt.js b/plejd/mqtt.js index 39afbb9..d0bcd08 100644 --- a/plejd/mqtt.js +++ b/plejd/mqtt.js @@ -133,7 +133,7 @@ class MqttClient extends EventEmitter { logger(`sending discovery for ${device.name}`); let payload = getDiscoveryPayload(device); - console.log(`discovered ${device.type}: ${device.name} with Plejd ID ${device.id}.`); + console.log(`plejd-mqtt: discovered ${device.type} named ${device.name} with PID ${device.id}.`); self.deviceMap[device.id] = payload.unique_id; diff --git a/plejd/package-lock.json b/plejd/package-lock.json index d1315fa..0aa67bd 100644 --- a/plejd/package-lock.json +++ b/plejd/package-lock.json @@ -14,9 +14,9 @@ } }, "@icanos/noble": { - "version": "1.9.2-6", - "resolved": "https://registry.npmjs.org/@icanos/noble/-/noble-1.9.2-6.tgz", - "integrity": "sha512-+NxEW7nNEueqX8MknTdno3AZeFode56tzN+dMDW0TJjW96XG822DhoHmHeQZRylTd74r/8M5c4Sb9x/m45yiPw==", + "version": "1.9.2-9", + "resolved": "https://registry.npmjs.org/@icanos/noble/-/noble-1.9.2-9.tgz", + "integrity": "sha512-u4zJS+Rl1cBJAd+Z0DiBCOqKhNOUor5fiT6Jtl3WAcF9QlAS+O22HC9yUaQB5DzcfpS5DpBdMpglUTG3xV/kQA==", "requires": { "@abandonware/bluetooth-hci-socket": "^0.5.3-3", "debug": "^4.1.1", @@ -24,11 +24,6 @@ "node-addon-api": "^1.1.0" } }, - "@types/zen-observable": { - "version": "0.8.0", - "resolved": "https://registry.npmjs.org/@types/zen-observable/-/zen-observable-0.8.0.tgz", - "integrity": "sha512-te5lMAWii1uEJ4FwLjzdlbw3+n0FZNOvFXHxQDKeT0dilh7HOzdMzV2TrJVUzq8ep7J4Na8OUYPRLSQkJHAlrg==" - }, "abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", @@ -139,11 +134,6 @@ "readable-stream": "> 1.0.0 < 3.0.0" } }, - "callsites": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", - "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==" - }, "chownr": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.3.tgz", @@ -321,11 +311,6 @@ "ext": "^1.1.2" } }, - "esm": { - "version": "3.2.25", - "resolved": "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz", - "integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==" - }, "event-emitter": { "version": "0.3.5", "resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz", @@ -565,14 +550,6 @@ "resolved": "https://registry.npmjs.org/is-negated-glob/-/is-negated-glob-1.0.0.tgz", "integrity": "sha1-aRC8pdqMleeEtXUbl2z1oQ/uNtI=" }, - "is-observable": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-observable/-/is-observable-1.1.0.tgz", - "integrity": "sha512-NqCa4Sa2d+u7BWc6CukaObG3Fh+CU9bvixbpcXYhy2VvYS7vVGIdAgnIS5Ks3A/cqk4rebLJ9s8zBstT2aKnIA==", - "requires": { - "symbol-observable": "^1.1.0" - } - }, "is-relative": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-relative/-/is-relative-1.0.0.tgz", @@ -841,11 +818,6 @@ "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" }, - "observable-fns": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/observable-fns/-/observable-fns-0.4.0.tgz", - "integrity": "sha512-2BFtEqza7sjLpgImAmagHK97mBwh3+bkwAZS/qF/4n2S8RzKsbdsdOczRBh+Piz7QgQZRAjTzI5vtxtOUgU+cQ==" - }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -1118,11 +1090,6 @@ "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=" }, - "symbol-observable": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-1.2.0.tgz", - "integrity": "sha512-e900nM8RRtGhlV36KGEU9k65K3mPb1WV70OdjfxlG2EAuM1noi/E/BaW/uMhL7bPEssK8QV57vN3esixjUvcXQ==" - }, "tar": { "version": "4.4.13", "resolved": "https://registry.npmjs.org/tar/-/tar-4.4.13.tgz", @@ -1175,20 +1142,6 @@ } } }, - "threads": { - "version": "1.0.0-beta.9", - "resolved": "https://registry.npmjs.org/threads/-/threads-1.0.0-beta.9.tgz", - "integrity": "sha512-ZjpQvqA78p+y4jtlhnQsKc8V9AwUvrWwOhy9FkFKWO24JHKte3oWllmjvUw896YqrZymsJvqJwlbUHV1CpVtKw==", - "requires": { - "@types/zen-observable": "^0.8.0", - "callsites": "^3.1.0", - "debug": "^4.1.1", - "is-observable": "^1.1.0", - "observable-fns": "^0.4.0", - "tiny-worker": ">= 2", - "zen-observable": "^0.8.14" - } - }, "through2": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/through2/-/through2-2.0.5.tgz", @@ -1207,14 +1160,6 @@ "xtend": "~4.0.0" } }, - "tiny-worker": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/tiny-worker/-/tiny-worker-2.3.0.tgz", - "integrity": "sha512-pJ70wq5EAqTAEl9IkGzA+fN0836rycEuz2Cn6yeZ6FRzlVS5IDOkFHpIoEsksPRQV34GDqXm65+OlnZqUSyK2g==", - "requires": { - "esm": "^3.2.25" - } - }, "to-absolute-glob": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/to-absolute-glob/-/to-absolute-glob-2.0.2.tgz", @@ -1337,11 +1282,6 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==" - }, - "zen-observable": { - "version": "0.8.15", - "resolved": "https://registry.npmjs.org/zen-observable/-/zen-observable-0.8.15.tgz", - "integrity": "sha512-PQ2PC7R9rslx84ndNBZB/Dkv8V8fZEpk83RLgXtYd0fwUgEjseMn1Dgajh2x6S8QbZAFa9p2qVCEuYZNgve0dQ==" } } } diff --git a/plejd/package.json b/plejd/package.json index 166653b..3e28578 100644 --- a/plejd/package.json +++ b/plejd/package.json @@ -10,4 +10,4 @@ "mqtt": "^3.0.0", "sleep": "^6.1.0" } -} \ No newline at end of file +} From 32821dfb2a7a82f6f9d20373f7a73c899248a723 Mon Sep 17 00:00:00 2001 From: icanos Date: Sat, 18 Jan 2020 16:06:48 +0000 Subject: [PATCH 4/6] bug fix --- plejd/ble.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plejd/ble.js b/plejd/ble.js index fbddafa..3be5d58 100644 --- a/plejd/ble.js +++ b/plejd/ble.js @@ -198,7 +198,7 @@ class PlejdService extends EventEmitter { } if (!uuid) { - this.sortedDevices = Object.values(this.devices).sort((a, b) => b.rssi - a.rssi); + sortedDevices = Object.values(this.devices).sort((a, b) => b.rssi - a.rssi); this.device = sortedDevices[this.deviceIdx]; } else { From b75f56043b3bf4929f39bf427c3aea524994ba99 Mon Sep 17 00:00:00 2001 From: icanos Date: Sat, 18 Jan 2020 18:02:18 +0000 Subject: [PATCH 5/6] fix --- plejd/ble.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plejd/ble.js b/plejd/ble.js index 3be5d58..87d31c3 100644 --- a/plejd/ble.js +++ b/plejd/ble.js @@ -198,7 +198,7 @@ class PlejdService extends EventEmitter { } if (!uuid) { - sortedDevices = Object.values(this.devices).sort((a, b) => b.rssi - a.rssi); + let sortedDevices = Object.values(this.devices).sort((a, b) => b.rssi - a.rssi); this.device = sortedDevices[this.deviceIdx]; } else { From 3c015660f4534d7165c9158a699d39d089166b1b Mon Sep 17 00:00:00 2001 From: icanos Date: Sat, 18 Jan 2020 18:23:03 +0000 Subject: [PATCH 6/6] upped version to fix issue --- 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 3436864..005b5f2 100644 --- a/plejd/config.json +++ b/plejd/config.json @@ -1,6 +1,6 @@ { "name": "Plejd", - "version": "0.2.9", + "version": "0.2.10", "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 e2360fe..291ead9 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.9"; +const version = "0.2.10"; async function main() { console.log('starting Plejd add-on v. ' + version);