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:
jangxx 2019-01-28 00:05:50 +01:00
parent 013cd28fd6
commit 87ca5befa7
3 changed files with 37 additions and 10 deletions

View File

@ -4,12 +4,37 @@ const {
} = require('homecontrol-control-base'); } = require('homecontrol-control-base');
const { Control } = require('magic-home'); 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 { class HCMagicHome extends HCColorLamp {
constructor(config) { constructor(config) {
super(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); this._sumanager = new StateUpdateManager(this._state);
} }
@ -62,7 +87,7 @@ class HCMagicHome extends HCColorLamp {
}); });
} }
toggle() { togglePower() {
if(this.state.on) { if(this.state.on) {
return this.turnOff(); return this.turnOff();
} else { } else {
@ -70,7 +95,7 @@ class HCMagicHome extends HCColorLamp {
} }
} }
changeBrightness(brightness) { setBrightness(brightness) {
let futureState = this.state; let futureState = this.state;
futureState.brightness = brightness; futureState.brightness = brightness;
let suid = this._sumanager.registerUpdate(futureState); let suid = this._sumanager.registerUpdate(futureState);
@ -84,7 +109,7 @@ class HCMagicHome extends HCColorLamp {
}); });
} }
changeColor(color) { setColor(color) {
let futureState = this.state; let futureState = this.state;
futureState.color = fillPartialHSL(color, futureState.color); futureState.color = fillPartialHSL(color, futureState.color);
let suid = this._sumanager.registerUpdate(futureState); let suid = this._sumanager.registerUpdate(futureState);
@ -157,7 +182,7 @@ class HCMagicHome extends HCColorLamp {
futureState.on = status.on; futureState.on = status.on;
futureState.brightness = extractBrightness(status.color); futureState.brightness = extractBrightness(status.color);
futureState.color = RGB_to_HSL(removeBrightness(status.color)); futureState.color = RGB_to_HSL(removeBrightness(status.color));
if (currentState.hash != futureState.hash) { if (currentState.hash != futureState.hash) {
// the state of the controller has changed externally // the state of the controller has changed externally
this._sumanager.insertConfirmedState(futureState); this._sumanager.insertConfirmedState(futureState);

9
package-lock.json generated
View File

@ -5,10 +5,11 @@
"requires": true, "requires": true,
"dependencies": { "dependencies": {
"homecontrol-control-base": { "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": { "requires": {
"merge-options": "1.0.1", "merge-options": "^1.0.1",
"node-object-hash": "1.4.1" "node-object-hash": "^1.4.1"
} }
}, },
"is-plain-obj": { "is-plain-obj": {
@ -26,7 +27,7 @@
"resolved": "https://registry.npmjs.org/merge-options/-/merge-options-1.0.1.tgz", "resolved": "https://registry.npmjs.org/merge-options/-/merge-options-1.0.1.tgz",
"integrity": "sha512-iuPV41VWKWBIOpBsjoxjDZw8/GbSfZ2mk7N1453bwMrfzdrIk7EzBd+8UVR6rkw67th7xnk9Dytl3J+lHPdxvg==", "integrity": "sha512-iuPV41VWKWBIOpBsjoxjDZw8/GbSfZ2mk7N1453bwMrfzdrIk7EzBd+8UVR6rkw67th7xnk9Dytl3J+lHPdxvg==",
"requires": { "requires": {
"is-plain-obj": "1.1.0" "is-plain-obj": "^1.1"
} }
}, },
"node-object-hash": { "node-object-hash": {

View File

@ -14,6 +14,7 @@
"license": "UNLICENSED", "license": "UNLICENSED",
"dependencies": { "dependencies": {
"homecontrol-control-base": "git+https://git.literalchaos.de/jan/homecontrol-control-base.git", "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"
} }
} }