hc-magichome/HCMagicHome.js
2019-01-25 16:15:03 +01:00

59 lines
998 B
JavaScript

const {
HCColorLamp
} = require('homecontrol-control-base');
const { Control } = require('magic-home');
class HCMagicHome extends HCColorLamp {
constructor(config) {
super(config);
this._control = new Control(this._configuration.address, this._configuration.characteristics);
}
turnOn() {
return new Promise((resolve, reject) => {
this._control.turnOn((err) => {
if (err) return reject(err);
this._state.on = true;
this.emit("state change", this.state);
return resolve(err);
});
});
}
turnOff() {
return new Promise((resolve, reject) => {
this._control.turnOff((err) => {
if (err) return reject(err);
this._state.on = false;
this.emit("state change", this.state);
return resolve(err);
});
});
}
toggle() {
if(this._state.on) {
return this.turnOff();
} else {
return this.turnOn();
}
}
changeBrightness(brightness) {
}
changeColor(hue, sat, light) {
}
pullState() {
}
}
module.exports = HCMagicHome;