updated dependency and glue code

This commit is contained in:
Jan Scheiper 2019-07-16 20:44:24 +02:00
parent 8ca3dece00
commit 4d968f6670
3 changed files with 25 additions and 51 deletions

View File

@ -14,64 +14,38 @@ class HCTPLink extends HCSwitch {
}
turnOn() {
return new Promise((resolve, reject) => {
let tp = new TPLink(this._configuration.address, (err) => {
if (err) return reject(err);
let tp = new TPLink(this._configuration.address);
tp.turnOn((parsed, resp) => {
if (!parsed) return reject("Could not parse response");
if (resp.system.set_relay_state.err_code == 0) {
this._state.on = true;
this.emit("state change", this.state);
return resolve();
} else {
return reject("Could not parse response");
}
});
});
return tp.turnOn().then(resp => {
if (resp.system.set_relay_state.err_code == 0) {
this._state.on = true;
this.emit("state change", this.state);
}
});
}
turnOff() {
return new Promise((resolve, reject) => {
let tp = new TPLink(this._configuration.address, (err) => {
if (err) return reject(err);
let tp = new TPLink(this._configuration.address);
tp.turnOff((parsed, resp) => {
if (!parsed) return reject("Could not parse response");
if (resp.system.set_relay_state.err_code == 0) {
this._state.on = false;
this.emit("state change", this.state);
return resolve();
} else {
return reject("Could not parse response");
}
});
});
return tp.turnOff().then(resp => {
if (resp.system.set_relay_state.err_code == 0) {
this._state.on = false;
this.emit("state change", this.state);
}
});
}
pullState() {
return new Promise((resolve, reject) => {
let tp = new TPLink(this._configuration.address, (err) => {
if (err) return reject(err);
let tp = new TPLink(this._configuration.address);
tp.getInfo((parsed, resp) => {
if (parsed) {
let hashBefore = this.state.hash;
return tp.query().then(resp => {
let hashBefore = this.state.hash;
this._state.on = (resp.system.get_sysinfo.relay_state == 1);
this._state.on = (resp.system.get_sysinfo.relay_state == 1);
if (this.state.hash != hashBefore) {
this.emit("state change", this.state);
}
}
return resolve();
});
});
if (this.state.hash != hashBefore) {
this.emit("state change", this.state);
}
});
}
}

8
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "hc-tplink-smartplug",
"version": "1.0.0",
"version": "1.1.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -31,9 +31,9 @@
"integrity": "sha512-JQVqSM5/mOaUoUhCYR0t1vgm8RFo7qpJtPvnoFCLeqQh1xrfmr3BCD3nGBnACzpIEF7F7EVgqGD3O4lao/BY/A=="
},
"tplink-smartplug-node": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/tplink-smartplug-node/-/tplink-smartplug-node-1.1.0.tgz",
"integrity": "sha1-aDaXXWRlpSo+tn0tB4kCjdPD3FE="
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/tplink-smartplug-node/-/tplink-smartplug-node-2.0.0.tgz",
"integrity": "sha512-IoZOLJjLb6/NwuHmfmljgFTf2NrKIXsHr2CkO8KgWhMAh9xJVsMdzmocOdGLokO2yWd1MxHzYPkxJQgtLxSNPA=="
}
}
}

View File

@ -1,6 +1,6 @@
{
"name": "hc-tplink-smartplug",
"version": "1.0.0",
"version": "1.1.0",
"description": "TP-Link Smart Plug Plugin for Homecontrol",
"main": "HCTPLink.js",
"scripts": {
@ -14,6 +14,6 @@
"license": "UNLICENSED",
"dependencies": {
"homecontrol-control-base": "git+https://git.literalchaos.de/jan/homecontrol-control-base.git",
"tplink-smartplug-node": "^1.1.0"
"tplink-smartplug-node": "^2.0.0"
}
}