From 7a3931cb3524fb49bfbeddbd8340e6e969ac7a0d Mon Sep 17 00:00:00 2001 From: Matthias Kleine Date: Fri, 12 Nov 2021 12:42:26 +0100 Subject: [PATCH] Added version check --- README.md | 1 + main.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/README.md b/README.md index 1dbe997..0b5ca32 100644 --- a/README.md +++ b/README.md @@ -208,6 +208,7 @@ show(); ### 1.5.0 * (klein0r) Fixed myData DIY data type **(BREAKING CHANGE - requires SimpleAPI 2.6.2 or later to use json parameter)** +* (klein0r) Added version check ### 1.4.1 diff --git a/main.js b/main.js index e0627be..81a1a74 100644 --- a/main.js +++ b/main.js @@ -15,6 +15,8 @@ class LaMetric extends utils.Adapter { name: adapterName, }); + this.supportedVersion = "2.2.2"; + this.refreshStateTimeout = null; this.refreshAppTimeout = null; @@ -442,6 +444,10 @@ class LaMetric extends utils.Adapter { (content, status) => { this.setState('info.connection', true, true); + if (this.isNewerVersion(content.os_version, this.supportedVersion)) { + this.log.warn("You should update your LaMetric Time - supported version of this adapter is " + this.supportedVersion + " (or later). Your current version is " + content.os_version); + } + this.setState('meta.name', {val: content.name, ack: true}); this.setState('meta.serial', {val: content.serial_number, ack: true}); this.setState('meta.version', {val: content.os_version, ack: true}); @@ -1056,6 +1062,18 @@ class LaMetric extends utils.Adapter { callback(); } } + + isNewerVersion(oldVer, newVer) { + const oldParts = oldVer.split('.'); + const newParts = newVer.split('.'); + for (var i = 0; i < newParts.length; i++) { + const a = ~~newParts[i]; // parse int + const b = ~~oldParts[i]; // parse int + if (a > b) return true; + if (a < b) return false; + } + return false; + } } // @ts-ignore parent is a valid property on module