Skip to content

Commit

Permalink
Added version check
Browse files Browse the repository at this point in the history
  • Loading branch information
klein0r committed Nov 12, 2021
1 parent 25c8eb1 commit 7a3931c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class LaMetric extends utils.Adapter {
name: adapterName,
});

this.supportedVersion = "2.2.2";

this.refreshStateTimeout = null;
this.refreshAppTimeout = null;

Expand Down Expand Up @@ -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});
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7a3931c

Please sign in to comment.