|
@@ -37,13 +37,19 @@
|
|
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
|
|
|
|
|
-var VueColor = require('vue-color');
|
|
|
|
|
|
|
+var Color = require('color');
|
|
|
|
|
+
|
|
|
|
|
+var Vue = require('vue'),
|
|
|
|
|
+ VueColor = require('vue-color');
|
|
|
|
|
|
|
|
module.exports = {
|
|
module.exports = {
|
|
|
props: ['light'],
|
|
props: ['light'],
|
|
|
data: function () {
|
|
data: function () {
|
|
|
return {
|
|
return {
|
|
|
- colors: {}
|
|
|
|
|
|
|
+ colors: {
|
|
|
|
|
+ hex: '#00ff00',
|
|
|
|
|
+ a: 0
|
|
|
|
|
+ }
|
|
|
};
|
|
};
|
|
|
},
|
|
},
|
|
|
http: {
|
|
http: {
|
|
@@ -57,23 +63,50 @@ module.exports = {
|
|
|
this.setProps({ reset: true });
|
|
this.setProps({ reset: true });
|
|
|
},
|
|
},
|
|
|
colorLoop: function () {
|
|
colorLoop: function () {
|
|
|
- this.setProps({ effect: 'colorloop' });
|
|
|
|
|
|
|
+ console.error('Not implemented')
|
|
|
},
|
|
},
|
|
|
setColor: function (color) {
|
|
setColor: function (color) {
|
|
|
- this.setProps({ color: color });
|
|
|
|
|
|
|
+ Vue.set(this.$props.light.state, 'rgb', Color(color).rgb().array());
|
|
|
|
|
+ },
|
|
|
|
|
+ setRgb: function (r, g, b) {
|
|
|
|
|
+ Vue.set(this.$props.light.state, 'rgb', [r, g, b]);
|
|
|
|
|
+ },
|
|
|
|
|
+ setBrightness: function (brightness) {
|
|
|
|
|
+ Vue.set(this.$props.light.state, 'bri', brightness);
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
watch: {
|
|
watch: {
|
|
|
light: {
|
|
light: {
|
|
|
handler: function (newVal, oldVal) {
|
|
handler: function (newVal, oldVal) {
|
|
|
- // this is just setting a new light
|
|
|
|
|
- if (newVal.id !== oldVal.id) return;
|
|
|
|
|
|
|
+ var that = this;
|
|
|
|
|
+
|
|
|
|
|
+ // this is setting a new light
|
|
|
|
|
+ if (newVal.id !== oldVal.id) {
|
|
|
|
|
+ console.log(newVal.state)
|
|
|
|
|
+
|
|
|
|
|
+ if (!newVal.state.rgb) return;
|
|
|
|
|
+
|
|
|
|
|
+ console.log(this.$data, Color.rgb(newVal.state.rgb).hex())
|
|
|
|
|
+ Vue.nextTick(function () {
|
|
|
|
|
+ that.$data.colors = {
|
|
|
|
|
+ hex: Color.rgb(newVal.state.rgb).hex(),
|
|
|
|
|
+ a: 255. / newVal.state.bri
|
|
|
|
|
+ };
|
|
|
|
|
+ });
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
console.log('light changed, commit changes', newVal, oldVal);
|
|
console.log('light changed, commit changes', newVal, oldVal);
|
|
|
|
|
|
|
|
this.$root.setLightProperties(this.$props.light);
|
|
this.$root.setLightProperties(this.$props.light);
|
|
|
},
|
|
},
|
|
|
deep: true
|
|
deep: true
|
|
|
|
|
+ },
|
|
|
|
|
+ colors: {
|
|
|
|
|
+ handler: function (newVal, oldVal) {
|
|
|
|
|
+ this.setRgb(newVal.rgba.r, newVal.rgba.g, newVal.rgba.b);
|
|
|
|
|
+ this.setBrightness(newVal.rgba.a * 255);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|