diff --git a/.travis.yml b/.travis.yml index 1505825..a90540a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,9 +3,9 @@ os: - osx language: node_js node_js: - - '4' - - '6' - - '8' + - '12' + - '14' + - '16' services: - mysql - postgresql diff --git a/README.md b/README.md index 1fce7f3..051d777 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,10 @@ Please check it https://www.smarthomejetzt.de/mit-iobroker-auf-eine-home-assista --> ## Changelog + +### __WORK IN PROGRESS__ +* (Apollon77) Fix start issue + ### 1.0.0 (2020-12-13) * (bluefox) added the support of compact mode diff --git a/appveyor.yml b/appveyor.yml index 73142d9..1f8433a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,9 +2,9 @@ version: 'test-{build}' os: Visual Studio 2013 environment: matrix: - - nodejs_version: '4' - - nodejs_version: '6' - - nodejs_version: '8' + - nodejs_version: '12' + - nodejs_version: '14' + - nodejs_version: '16' platform: - x86 - x64 diff --git a/lib/hass.js b/lib/hass.js index af680eb..029174c 100644 --- a/lib/hass.js +++ b/lib/hass.js @@ -23,6 +23,7 @@ function HASS(options, log) { const requests = {}; let connected; let connectTimeout = null; + let closed = false; function subscribeEvents(socket, callback) { if (socket && typeof socket.send === 'function') { @@ -184,7 +185,7 @@ function HASS(options, log) { that.emit('disconnected'); } - if (!connectTimeout) { + if (!connectTimeout && !closed) { setTimeout(() => { connectTimeout = null; that.connect(); @@ -248,6 +249,17 @@ function HASS(options, log) { initSocket(this.socket); }; + this.close = function () { + if (connectTimeout) { + clearTimeout(connectTimeout); + connectTimeout = null; + } + closed = true; + if (this.socket) { + this.socket.close(); + } + } + return this; } diff --git a/main.js b/main.js index de220e9..20d580f 100644 --- a/main.js +++ b/main.js @@ -62,6 +62,11 @@ function startAdapter(options) { return adapter; } +function stop(callback) { + hass && hass.close(); + callback && callback(); +} + function getUnit(name) { name = name.toLowerCase(); if (name.indexOf('temperature') !== -1) {