updated magic-home to new version 2.0
This commit is contained in:
parent
c56caf3de8
commit
c650a60703
154
HCMagicHome.js
154
HCMagicHome.js
@ -72,10 +72,16 @@ class HCMagicHome extends HCColorLamp {
|
|||||||
futureState.on = true;
|
futureState.on = true;
|
||||||
let suid = this._sumanager.registerUpdate(futureState);
|
let suid = this._sumanager.registerUpdate(futureState);
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return this._control.setPower(true).then(success => {
|
||||||
this._control.turnOn((err) => {
|
this._sumanager.confirmUpdate(suid);
|
||||||
updateHelper(this, err, suid, resolve, reject);
|
|
||||||
});
|
if (this._sumanager.highestConfirmedId == suid) {
|
||||||
|
this.emit("state change", this.state);
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}).catch(err => {
|
||||||
|
this._sumanager.rejectUpdate(suid);
|
||||||
|
throw err;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,10 +90,16 @@ class HCMagicHome extends HCColorLamp {
|
|||||||
futureState.on = false;
|
futureState.on = false;
|
||||||
let suid = this._sumanager.registerUpdate(futureState);
|
let suid = this._sumanager.registerUpdate(futureState);
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return this._control.setPower(false).then(success => {
|
||||||
this._control.turnOff((err) => {
|
this._sumanager.confirmUpdate(suid);
|
||||||
updateHelper(this, err, suid, resolve, reject);
|
|
||||||
});
|
if (this._sumanager.highestConfirmedId == suid) {
|
||||||
|
this.emit("state change", this.state);
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}).catch(err => {
|
||||||
|
this._sumanager.rejectUpdate(suid);
|
||||||
|
throw err;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,12 +116,18 @@ class HCMagicHome extends HCColorLamp {
|
|||||||
futureState.brightness = brightness;
|
futureState.brightness = brightness;
|
||||||
let suid = this._sumanager.registerUpdate(futureState);
|
let suid = this._sumanager.registerUpdate(futureState);
|
||||||
|
|
||||||
let rgbColor = HSL_to_RGB(futureState.color);
|
let { red, green, blue } = HSL_to_RGB(futureState.color);
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return this._control.setColorWithBrightness(red, green, blue, futureState.brightness).then(success => {
|
||||||
this._control.setColorWithBrightness(rgbColor.red, rgbColor.green, rgbColor.blue, futureState.brightness, (err, success) => {
|
this._sumanager.confirmUpdate(suid);
|
||||||
updateHelper(this, err, suid, resolve, reject, success);
|
|
||||||
});
|
if (this._sumanager.highestConfirmedId == suid) {
|
||||||
|
this.emit("state change", this.state);
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}).catch(err => {
|
||||||
|
this._sumanager.rejectUpdate(suid);
|
||||||
|
throw err;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,12 +136,18 @@ class HCMagicHome extends HCColorLamp {
|
|||||||
futureState.color = fillPartialHSL(color, futureState.color);
|
futureState.color = fillPartialHSL(color, futureState.color);
|
||||||
let suid = this._sumanager.registerUpdate(futureState);
|
let suid = this._sumanager.registerUpdate(futureState);
|
||||||
|
|
||||||
let rgbColor = HSL_to_RGB(futureState.color);
|
let { red, green, blue } = HSL_to_RGB(futureState.color);
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return this._control.setColorWithBrightness(red, green, blue, futureState.brightness).then(success => {
|
||||||
this._control.setColorWithBrightness(rgbColor.red, rgbColor.green, rgbColor.blue, futureState.brightness, (err, success) => {
|
this._sumanager.confirmUpdate(suid);
|
||||||
updateHelper(this, err, suid, resolve, reject, success);
|
|
||||||
});
|
if (this._sumanager.highestConfirmedId == suid) {
|
||||||
|
this.emit("state change", this.state);
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}).catch(err => {
|
||||||
|
this._sumanager.rejectUpdate(suid);
|
||||||
|
throw err;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,84 +173,68 @@ class HCMagicHome extends HCColorLamp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let futureState = this.state;
|
let futureState = this.state;
|
||||||
|
let promise;
|
||||||
|
|
||||||
if(effect == 'none') {
|
if(effect == 'none') {
|
||||||
futureState.effect = "none";
|
futureState.effect = "none";
|
||||||
let suid = this._sumanager.registerUpdate(futureState);
|
|
||||||
|
|
||||||
let rgbColor = HSL_to_RGB(futureState.color);
|
let { red, green, blue } = HSL_to_RGB(futureState.color);
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
promise = this._control.setColorWithBrightness(red, green, blue, futureState.brightness);
|
||||||
this._control.setColorWithBrightness(rgbColor.red, rgbColor.green, rgbColor.blue, futureState.brightness, (err, success) => {
|
|
||||||
updateHelper(this, err, suid, resolve, reject, success);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
futureState.effect = id; // id is "valid" / can be parsed
|
futureState.effect = id; // id is "valid" / can be parsed
|
||||||
let suid = this._sumanager.registerUpdate(futureState);
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
promise = this._control.setPattern(effect, speed);
|
||||||
this._control.setPattern(effect, speed, (err, success) => {
|
|
||||||
updateHelper(this, err, suid, resolve, reject, success);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let suid = this._sumanager.registerUpdate(futureState);
|
||||||
|
|
||||||
|
return promise.then(success => {
|
||||||
|
this._sumanager.confirmUpdate(suid);
|
||||||
|
|
||||||
|
if (this._sumanager.highestConfirmedId == suid) {
|
||||||
|
this.emit("state change", this.state);
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}).catch(err => {
|
||||||
|
this._sumanager.rejectUpdate(suid);
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pullState() {
|
pullState() {
|
||||||
return new Promise((resolve, reject) => {
|
return this._control.queryState().then(status => {
|
||||||
this._control.queryState((err, status) => {
|
let currentState = this.state;
|
||||||
if(err) return reject(err);
|
let futureState = currentState.clone();
|
||||||
|
|
||||||
let currentState = this.state;
|
//console.log(status);
|
||||||
let futureState = currentState.clone();
|
|
||||||
|
|
||||||
//console.log(status);
|
futureState.on = status.on;
|
||||||
|
|
||||||
futureState.on = status.on;
|
let effect = (status.mode != 'color' && status.mode != 'warm_white' && status.mode != 'special') ? status.mode : 'none';
|
||||||
|
if(effect != 'none') {
|
||||||
|
let speed = (status.speed > 80) ? 'fast' : (status.speed > 30) ? 'medium' : 'slow';
|
||||||
|
futureState.effect = speed + '-' + effect;
|
||||||
|
} else {
|
||||||
|
futureState.effect = 'none';
|
||||||
|
}
|
||||||
|
|
||||||
let effect = (status.mode != 'color' && status.mode != 'warm_white' && status.mode != 'special') ? status.mode : 'none';
|
if (futureState.effect == 'none') { // only update color when no effects are playing
|
||||||
if(effect != 'none') {
|
futureState.brightness = extractBrightness(status.color);
|
||||||
let speed = (status.speed > 80) ? 'fast' : (status.speed > 30) ? 'medium' : 'slow';
|
futureState.color = RGB_to_HSL(removeBrightness(status.color));
|
||||||
futureState.effect = speed + '-' + effect;
|
}
|
||||||
} else {
|
|
||||||
futureState.effect = 'none';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (futureState.effect == 'none') { // only update color when no effects are playing
|
if (currentState.hash != futureState.hash) {
|
||||||
futureState.brightness = extractBrightness(status.color);
|
// the state of the controller has changed externally
|
||||||
futureState.color = RGB_to_HSL(removeBrightness(status.color));
|
this._sumanager.insertConfirmedState(futureState);
|
||||||
}
|
this.emit("state change", this.state);
|
||||||
|
}
|
||||||
if (currentState.hash != futureState.hash) {
|
|
||||||
// the state of the controller has changed externally
|
|
||||||
this._sumanager.insertConfirmedState(futureState);
|
|
||||||
this.emit("state change", this.state);
|
|
||||||
}
|
|
||||||
|
|
||||||
return resolve();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = HCMagicHome;
|
module.exports = HCMagicHome;
|
||||||
|
|
||||||
function updateHelper(self, err, suid, resolve, reject, resolveVal) {
|
|
||||||
if (err) {
|
|
||||||
self._sumanager.rejectUpdate(suid);
|
|
||||||
return reject(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
self._sumanager.confirmUpdate(suid);
|
|
||||||
|
|
||||||
if (self._sumanager.highestConfirmedId == suid) {
|
|
||||||
self.emit("state change", self.state);
|
|
||||||
}
|
|
||||||
|
|
||||||
return resolve(resolveVal);
|
|
||||||
}
|
|
||||||
|
|
||||||
function HSL_to_RGB(hsl) {
|
function HSL_to_RGB(hsl) {
|
||||||
var h = hsl.hue / 360;
|
var h = hsl.hue / 360;
|
||||||
var s = hsl.sat / 100;
|
var s = hsl.sat / 100;
|
||||||
|
|||||||
16
package-lock.json
generated
16
package-lock.json
generated
@ -1,11 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "hc-magichome",
|
"name": "hc-magichome",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"homecontrol-control-base": {
|
"homecontrol-control-base": {
|
||||||
"version": "git+https://git.literalchaos.de/jan/homecontrol-control-base.git#96b0c33583b893e236567e11082b1d093382a79e",
|
"version": "git+https://git.literalchaos.de/jan/homecontrol-control-base.git#b7ed807affe888d61efd9dbff3d55bcc128215b7",
|
||||||
"from": "git+https://git.literalchaos.de/jan/homecontrol-control-base.git",
|
"from": "git+https://git.literalchaos.de/jan/homecontrol-control-base.git",
|
||||||
"requires": {
|
"requires": {
|
||||||
"merge-options": "^1.0.1",
|
"merge-options": "^1.0.1",
|
||||||
@ -18,9 +18,9 @@
|
|||||||
"integrity": "sha1-caUMhCnfync8kqOQpKA7OfzVHT4="
|
"integrity": "sha1-caUMhCnfync8kqOQpKA7OfzVHT4="
|
||||||
},
|
},
|
||||||
"magic-home": {
|
"magic-home": {
|
||||||
"version": "1.4.0",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/magic-home/-/magic-home-1.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/magic-home/-/magic-home-2.0.1.tgz",
|
||||||
"integrity": "sha512-hSq3C/9rbEH3RB2t2rG/LsSb2vpalzIGh/mLKJyjaki3Wbvt9ss+2OUJ1JsAOAjjgkvxDEfbQ044yFsHZUS75A=="
|
"integrity": "sha512-nC2XB9ENZf4afGJFvTnKKqxx+xuFOE1TjKVYiSY9B5aSkE88Z4Q5bYeVihoTEG8r8pOEZSYHnuLIi2tPXwsCwg=="
|
||||||
},
|
},
|
||||||
"merge-options": {
|
"merge-options": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
@ -31,9 +31,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node-object-hash": {
|
"node-object-hash": {
|
||||||
"version": "1.4.1",
|
"version": "1.4.2",
|
||||||
"resolved": "https://registry.npmjs.org/node-object-hash/-/node-object-hash-1.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/node-object-hash/-/node-object-hash-1.4.2.tgz",
|
||||||
"integrity": "sha512-JQVqSM5/mOaUoUhCYR0t1vgm8RFo7qpJtPvnoFCLeqQh1xrfmr3BCD3nGBnACzpIEF7F7EVgqGD3O4lao/BY/A=="
|
"integrity": "sha512-UdS4swXs85fCGWWf6t6DMGgpN/vnlKeSGEQ7hJcrs7PBFoxoKLmibc3QRb7fwiYsjdL7PX8iI/TMSlZ90dgHhQ=="
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hc-magichome",
|
"name": "hc-magichome",
|
||||||
"version": "1.0.1",
|
"version": "1.0.2",
|
||||||
"description": "Magic Home Plugin for Homecontrol",
|
"description": "Magic Home Plugin for Homecontrol",
|
||||||
"main": "HCMagicHome.js",
|
"main": "HCMagicHome.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -14,7 +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": "^2.0.1",
|
||||||
"merge-options": "^1.0.1"
|
"merge-options": "^1.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user