initial comit with all the functionality

This commit is contained in:
Jan Scheiper 2021-12-22 10:03:00 +01:00
commit 86a8a83de5
4 changed files with 133 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

58
HCMeross.js Normal file
View File

@ -0,0 +1,58 @@
const {
HCSwitch,
} = require("homecontrol-control-base");
const { MerossSmartPlug } = require("meross-local");
class HCMeross extends HCSwitch {
constructor(config) {
super(config);
if (!("address" in this._configuration)) {
throw new Error(`Required configuration field "address" is missing`);
}
if (!("key" in this._configuration)) {
throw new Error(`Required configuration field "key" is missing`);
}
this._channel = ("channel" in this._configuration) ? this._configuration.channel : 0;
this._plug = new MerossSmartPlug(this._configuration.address, this._configuration.key);
}
static get version() {
return require("./package.json").version;
}
turnOn() {
return this._plug.turnOn(this._channel).then(resp => {
if (resp.header.method == "SETACK") {
this._state.on = true;
this.emit("state change", this.state);
}
});
}
turnOff() {
return this._plug.turnOff(this._channel).then(resp => {
if (resp.header.method == "SETACK") {
this._state.on = false;
this.emit("state change", this.state);
}
});
}
pullState() {
return this._plug.getPower(this._channel).then(power => {
let hashBefore = this.state.hash;
this._state.on = power;
if (this.state.hash != hashBefore) {
this.emit("state change", this.state);
}
});
}
}
module.exports = HCMeross;

55
package-lock.json generated Normal file
View File

@ -0,0 +1,55 @@
{
"name": "hc-meross-smartplug",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"axios": {
"version": "0.24.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.24.0.tgz",
"integrity": "sha512-Q6cWsys88HoPgAaFAVUb0WpPk0O8iTeisR9IMqy9G8AbO4NlpVknrnQS03zzF9PGAWgO3cgletO3VjV/P7VztA==",
"requires": {
"follow-redirects": "^1.14.4"
}
},
"follow-redirects": {
"version": "1.14.6",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.6.tgz",
"integrity": "sha512-fhUl5EwSJbbl8AR+uYL2KQDxLkdSjZGR36xy46AO7cOMTrCMON6Sa28FmAnC2tRTDbd/Uuzz3aJBv7EBN7JH8A=="
},
"homecontrol-control-base": {
"version": "git+https://git.literalchaos.de/jan/homecontrol-control-base.git#37eb940fbda9c423834ca3b0f6895753f446ed88",
"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"
}
},
"meross-local": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/meross-local/-/meross-local-1.0.0.tgz",
"integrity": "sha512-KIyT1lwv2azclTm2Hmzk1bjbIZzcK3jllCR36vkJH8h5lZt7DLpP0HkW7Yn6ZieOfzIqlJkl4ky3O331/YBoFA==",
"requires": {
"axios": "^0.24.0"
}
},
"node-object-hash": {
"version": "1.4.2",
"resolved": "https://registry.npmjs.org/node-object-hash/-/node-object-hash-1.4.2.tgz",
"integrity": "sha512-UdS4swXs85fCGWWf6t6DMGgpN/vnlKeSGEQ7hJcrs7PBFoxoKLmibc3QRb7fwiYsjdL7PX8iI/TMSlZ90dgHhQ=="
}
}
}

19
package.json Normal file
View File

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