added new config parameter and upped version

This commit is contained in:
Marcus Westin 2020-03-03 16:22:30 +01:00
parent 49214bf8f4
commit b7f3f65ff0
4 changed files with 14 additions and 15 deletions

View file

@ -40,7 +40,7 @@ const GATT_SERVICE_ID = 'org.bluez.GattService1';
const GATT_CHRC_ID = 'org.bluez.GattCharacteristic1'; const GATT_CHRC_ID = 'org.bluez.GattCharacteristic1';
class PlejdService extends EventEmitter { class PlejdService extends EventEmitter {
constructor(cryptoKey, devices, sceneManager, connectionTimeout, keepAlive = false) { constructor(cryptoKey, devices, sceneManager, connectionTimeout, writeQueueWaitTime, keepAlive = false) {
super(); super();
this.cryptoKey = Buffer.from(cryptoKey.replace(/-/g, ''), 'hex'); this.cryptoKey = Buffer.from(cryptoKey.replace(/-/g, ''), 'hex');
@ -53,6 +53,7 @@ class PlejdService extends EventEmitter {
this.devices = devices; this.devices = devices;
this.connectEventHooked = false; this.connectEventHooked = false;
this.connectionTimeout = connectionTimeout; this.connectionTimeout = connectionTimeout;
this.writeQueueWaitTime = writeQueueWaitTime;
this.writeQueue = []; this.writeQueue = [];
this.writeQueueRef = null; this.writeQueueRef = null;
@ -430,13 +431,7 @@ class PlejdService extends EventEmitter {
console.log('startWriteQueue()'); console.log('startWriteQueue()');
clearInterval(this.writeQueueRef); clearInterval(this.writeQueueRef);
this.writeQueueRef = setTimeout(() => this.runWriteQueue(), 400); this.writeQueueRef = setTimeout(() => this.runWriteQueue(), this.writeQueueWaitTime);
// this.writeQueueRef = setInterval(async () => {
// while (this.writeQueue.length > 0) {
// const data = this.writeQueue.pop();
// await this.write(data);
// }
// }, 400);
} }
async runWriteQueue() { async runWriteQueue() {
@ -445,7 +440,7 @@ class PlejdService extends EventEmitter {
await this.write(data, true); await this.write(data, true);
} }
this.writeQueueRef = setTimeout(() => this.runWriteQueue(), 400); this.writeQueueRef = setTimeout(() => this.runWriteQueue(), this.writeQueueWaitTime);
} }
async _processPlejdService(path, characteristics) { async _processPlejdService(path, characteristics) {

View file

@ -1,6 +1,6 @@
{ {
"name": "Plejd", "name": "Plejd",
"version": "0.4.1", "version": "0.4.2",
"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/",
@ -23,7 +23,8 @@
"mqttUsername": "", "mqttUsername": "",
"mqttPassword": "", "mqttPassword": "",
"includeRoomsAsLights": false, "includeRoomsAsLights": false,
"connectionTimeout": 2 "connectionTimeout": 2,
"writeQueueWaitTime": 400
}, },
"schema": { "schema": {
"site": "str", "site": "str",
@ -33,6 +34,7 @@
"mqttUsername": "str", "mqttUsername": "str",
"mqttPassword": "str", "mqttPassword": "str",
"includeRoomsAsLights": "bool", "includeRoomsAsLights": "bool",
"connectionTimeout": "int" "connectionTimeout": "int",
"writeQueueWaitTime": "int"
} }
} }

View file

@ -4,7 +4,7 @@ const fs = require('fs');
const PlejdService = require('./ble.bluez'); const PlejdService = require('./ble.bluez');
const SceneManager = require('./scene.manager'); const SceneManager = require('./scene.manager');
const version = "0.4.1"; const version = "0.4.2";
async function main() { async function main() {
console.log('starting Plejd add-on v. ' + version); console.log('starting Plejd add-on v. ' + version);
@ -32,7 +32,7 @@ async function main() {
// init the BLE interface // init the BLE interface
const sceneManager = new SceneManager(site, devices); const sceneManager = new SceneManager(site, devices);
const plejd = new PlejdService(cryptoKey, devices, sceneManager, config.connectionTimeout, true); const plejd = new PlejdService(cryptoKey, devices, sceneManager, config.connectionTimeout, config.writeQueueWaitTime, true);
plejd.on('connectFailed', () => { plejd.on('connectFailed', () => {
console.log('plejd-ble: were unable to connect, will retry connection in 10 seconds.'); console.log('plejd-ble: were unable to connect, will retry connection in 10 seconds.');
setTimeout(() => { setTimeout(() => {

View file

@ -10,6 +10,7 @@ MQTTUSERNAME=$(jq --raw-output ".mqttUsername" $CONFIG_PATH)
MQTTPASSWORD=$(jq --raw-output ".mqttPassword" $CONFIG_PATH) MQTTPASSWORD=$(jq --raw-output ".mqttPassword" $CONFIG_PATH)
INCLUDEROOMSASLIGHTS=$(jq --raw-output ".includeRoomsAsLights" $CONFIG_PATH) INCLUDEROOMSASLIGHTS=$(jq --raw-output ".includeRoomsAsLights" $CONFIG_PATH)
CONNECTIONTIMEOUT=$(jq --raw-output ".connectionTimeout" $CONFIG_PATH) CONNECTIONTIMEOUT=$(jq --raw-output ".connectionTimeout" $CONFIG_PATH)
WRITEQUEUEWAITTIME=$(jq --raw-output ".writeQueueWaitTime" $CONFIG_PATH)
PLEJD_PATH=/data/plejd.json PLEJD_PATH=/data/plejd.json
PLEJD_CONFIG="{ PLEJD_CONFIG="{
@ -20,7 +21,8 @@ PLEJD_CONFIG="{
\"mqttUsername\": \"$MQTTUSERNAME\", \"mqttUsername\": \"$MQTTUSERNAME\",
\"mqttPassword\": \"$MQTTPASSWORD\", \"mqttPassword\": \"$MQTTPASSWORD\",
\"includeRoomsAsLights\": \"$INCLUDEROOMSASLIGHTS\", \"includeRoomsAsLights\": \"$INCLUDEROOMSASLIGHTS\",
\"connectionTimeout\": \"$CONNECTIONTIMEOUT\" \"connectionTimeout\": \"$CONNECTIONTIMEOUT\",
\"writeQueueWaitTime\": \"$WRITEQUEUEWAITTIME\"
} }
" "