version 1.0.0

This commit is contained in:
jangxx 2019-01-29 22:10:28 +01:00
commit 8ca3dece00
4 changed files with 138 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules/

79
HCTPLink.js Normal file
View File

@ -0,0 +1,79 @@
const {
HCSwitch
} = require('homecontrol-control-base');
const TPLink = require('tplink-smartplug-node');
class HCTPLink extends HCSwitch {
constructor(config) {
super(config);
if (!("address" in this._configuration)) {
throw new Error(`Required configuration field "address" is missing"`);
}
}
turnOn() {
return new Promise((resolve, reject) => {
let tp = new TPLink(this._configuration.address, (err) => {
if (err) return reject(err);
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");
}
});
});
});
}
turnOff() {
return new Promise((resolve, reject) => {
let tp = new TPLink(this._configuration.address, (err) => {
if (err) return reject(err);
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");
}
});
});
});
}
pullState() {
return new Promise((resolve, reject) => {
let tp = new TPLink(this._configuration.address, (err) => {
if (err) return reject(err);
tp.getInfo((parsed, resp) => {
if (parsed) {
let hashBefore = this.state.hash;
this._state.on = (resp.system.get_sysinfo.relay_state == 1);
if (this.state.hash != hashBefore) {
this.emit("state change", this.state);
}
}
return resolve();
});
});
});
}
}
module.exports = HCTPLink;

39
package-lock.json generated Normal file
View File

@ -0,0 +1,39 @@
{
"name": "hc-tplink-smartplug",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"homecontrol-control-base": {
"version": "git+https://git.literalchaos.de/jan/homecontrol-control-base.git#809acfad8245dad9d974cba5b1eff2dfc5419cc9",
"from": "git+https://git.literalchaos.de/jan/homecontrol-control-base.git",
"requires": {
"merge-options": "^1.0.1",
"node-object-hash": "^1.4.1"
}
},
"is-plain-obj": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-1.1.0.tgz",
"integrity": "sha1-caUMhCnfync8kqOQpKA7OfzVHT4="
},
"merge-options": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/merge-options/-/merge-options-1.0.1.tgz",
"integrity": "sha512-iuPV41VWKWBIOpBsjoxjDZw8/GbSfZ2mk7N1453bwMrfzdrIk7EzBd+8UVR6rkw67th7xnk9Dytl3J+lHPdxvg==",
"requires": {
"is-plain-obj": "^1.1"
}
},
"node-object-hash": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/node-object-hash/-/node-object-hash-1.4.1.tgz",
"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="
}
}
}

19
package.json Normal file
View File

@ -0,0 +1,19 @@
{
"name": "hc-tplink-smartplug",
"version": "1.0.0",
"description": "TP-Link Smart Plug Plugin for Homecontrol",
"main": "HCTPLink.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git@git.literalchaos.de:jan/hc-tplink-smartplug.git"
},
"author": "Jan Scheiper",
"license": "UNLICENSED",
"dependencies": {
"homecontrol-control-base": "git+https://git.literalchaos.de/jan/homecontrol-control-base.git",
"tplink-smartplug-node": "^1.1.0"
}
}