From 0b13b21861cf8b9bbc719dd8e5f4e9095331772a Mon Sep 17 00:00:00 2001 From: jangxx Date: Mon, 28 Jan 2019 00:04:30 +0100 Subject: [PATCH] renamed some of the functions, fixed a few bugs here and there --- ColorlampBase.js | 6 +++--- StateUpdateManager.js | 2 +- SwitchBase.js | 2 +- package-lock.json | 2 +- states/ColorlampState.js | 2 ++ states/SwitchState.js | 18 +++++++++++++++--- 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/ColorlampBase.js b/ColorlampBase.js index 89ee47c..55e743d 100644 --- a/ColorlampBase.js +++ b/ColorlampBase.js @@ -22,11 +22,11 @@ class HCColorlamp extends HCControlBase { return Promise.reject("Not implemented"); } - toggle() { + togglePower() { return Promise.reject("Not implemented"); } - changeBrightness(brightness) { + setBrightness(brightness) { return Promise.reject("Not implemented"); } @@ -38,7 +38,7 @@ class HCColorlamp extends HCControlBase { * @param {Number} color.sat Saturation * @param {Number} color.l Lightness */ - changeColor(color) { + setColor(color) { return Promise.reject("Not implemented"); } diff --git a/StateUpdateManager.js b/StateUpdateManager.js index 6fd890c..d00c6ec 100644 --- a/StateUpdateManager.js +++ b/StateUpdateManager.js @@ -52,7 +52,7 @@ class StateUpdateManager { * @param {Object} state */ insertConfirmedState(state) { - let suid = this.registerUpdate(); + let suid = this.registerUpdate(state); this.confirmUpdate(suid); } diff --git a/SwitchBase.js b/SwitchBase.js index 5b22532..b031ca1 100644 --- a/SwitchBase.js +++ b/SwitchBase.js @@ -18,7 +18,7 @@ class HCSwitchBase extends HCControlBase { return Promise.reject(); } - toggle() { + togglePower() { return Promise.reject(); } } diff --git a/package-lock.json b/package-lock.json index 58097d8..0d4a531 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,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": { diff --git a/states/ColorlampState.js b/states/ColorlampState.js index 46889df..3212506 100644 --- a/states/ColorlampState.js +++ b/states/ColorlampState.js @@ -4,6 +4,8 @@ const BaseState = require('./BaseState'); class ColorlampState extends BaseState { constructor(cloneObj) { + super(); + let cloneState = mergeOptions(ColorlampState.default, cloneObj); this.on = cloneState.on; diff --git a/states/SwitchState.js b/states/SwitchState.js index 2ffd14c..2c9b0a4 100644 --- a/states/SwitchState.js +++ b/states/SwitchState.js @@ -1,13 +1,25 @@ +const mergeOptions = require('merge-options'); + const BaseState = require('./BaseState'); class SwitchState extends BaseState { - constructor() { - this.on = false; + constructor(cloneObj) { + super(); + + let cloneState = mergeOptions(SwitchState.default, cloneObj); + + this.on = cloneState.on; + } + + static get default() { + return { + on: false + }; } get asObj() { return { - on: this.on + on: this.on, }; } }