adhered to the newly changed base fucntion names, added type option which encompasses several characteristics and closely resembles the old controls functionality
This commit is contained in:
parent
013cd28fd6
commit
87ca5befa7
@ -4,12 +4,37 @@ const {
|
||||
} = require('homecontrol-control-base');
|
||||
|
||||
const { Control } = require('magic-home');
|
||||
const mergeOptions = require('merge-options');
|
||||
|
||||
const types = Object.freeze({
|
||||
type1: {
|
||||
rgb_min_0: true,
|
||||
ww_min_0: true,
|
||||
set_color_magic_bytes: [0xf0, 0x0f],
|
||||
wait_for_reply: true
|
||||
},
|
||||
type2: {
|
||||
rgb_min_0: false,
|
||||
ww_min_0: false,
|
||||
set_color_magic_bytes: [0x00, 0x0f],
|
||||
wait_for_reply: false
|
||||
},
|
||||
});
|
||||
|
||||
class HCMagicHome extends HCColorLamp {
|
||||
constructor(config) {
|
||||
super(config);
|
||||
|
||||
this._control = new Control(this._configuration.address, this._configuration.characteristics);
|
||||
let type = "type1";
|
||||
if (this._configuration.type != undefined) {
|
||||
type = this._configuration.type;
|
||||
}
|
||||
|
||||
if (!(type in types)) throw new Error(`Type "${type}" could not be found`);
|
||||
|
||||
let characteristics = mergeOptions(types[type], this._configuration.characteristics);
|
||||
|
||||
this._control = new Control(this._configuration.address, characteristics);
|
||||
|
||||
this._sumanager = new StateUpdateManager(this._state);
|
||||
}
|
||||
@ -62,7 +87,7 @@ class HCMagicHome extends HCColorLamp {
|
||||
});
|
||||
}
|
||||
|
||||
toggle() {
|
||||
togglePower() {
|
||||
if(this.state.on) {
|
||||
return this.turnOff();
|
||||
} else {
|
||||
@ -70,7 +95,7 @@ class HCMagicHome extends HCColorLamp {
|
||||
}
|
||||
}
|
||||
|
||||
changeBrightness(brightness) {
|
||||
setBrightness(brightness) {
|
||||
let futureState = this.state;
|
||||
futureState.brightness = brightness;
|
||||
let suid = this._sumanager.registerUpdate(futureState);
|
||||
@ -84,7 +109,7 @@ class HCMagicHome extends HCColorLamp {
|
||||
});
|
||||
}
|
||||
|
||||
changeColor(color) {
|
||||
setColor(color) {
|
||||
let futureState = this.state;
|
||||
futureState.color = fillPartialHSL(color, futureState.color);
|
||||
let suid = this._sumanager.registerUpdate(futureState);
|
||||
|
||||
9
package-lock.json
generated
9
package-lock.json
generated
@ -5,10 +5,11 @@
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"homecontrol-control-base": {
|
||||
"version": "git+https://git.literalchaos.de/jan/homecontrol-control-base.git#5d58715922bdc7abf909637f8f959e4a95c3c53b",
|
||||
"version": "git+https://git.literalchaos.de/jan/homecontrol-control-base.git#96b0c33583b893e236567e11082b1d093382a79e",
|
||||
"from": "git+https://git.literalchaos.de/jan/homecontrol-control-base.git",
|
||||
"requires": {
|
||||
"merge-options": "1.0.1",
|
||||
"node-object-hash": "1.4.1"
|
||||
"merge-options": "^1.0.1",
|
||||
"node-object-hash": "^1.4.1"
|
||||
}
|
||||
},
|
||||
"is-plain-obj": {
|
||||
@ -26,7 +27,7 @@
|
||||
"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.0"
|
||||
"is-plain-obj": "^1.1"
|
||||
}
|
||||
},
|
||||
"node-object-hash": {
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
"license": "UNLICENSED",
|
||||
"dependencies": {
|
||||
"homecontrol-control-base": "git+https://git.literalchaos.de/jan/homecontrol-control-base.git",
|
||||
"magic-home": "^1.4.0"
|
||||
"magic-home": "^1.4.0",
|
||||
"merge-options": "^1.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user