From 027d7e08b244a35a07bca69360adcb23717fe123 Mon Sep 17 00:00:00 2001 From: Egor Date: Tue, 11 Aug 2015 00:15:42 -0700 Subject: [PATCH] Adding new icons to display the lights connected in the system, adding brightness control --- app/components/bridge-controls.js | 98 +++++++++++++++++++- app/templates/components/bridge-controls.hbs | 7 +- config/environment.js | 4 +- public/assets/images/lights/a19.svg | 32 +++++++ public/assets/images/lights/br30.svg | 48 ++++++++++ public/assets/images/lights/gu10.svg | 18 ++++ public/assets/images/lights/huego.svg | 23 +++++ public/assets/images/lights/lc_aura.svg | 32 +++++++ public/assets/images/lights/lc_bloom.svg | 30 ++++++ public/assets/images/lights/lc_iris.svg | 29 ++++++ public/assets/images/lights/lightstrip.svg | 45 +++++++++ public/assets/images/lights/storylight.svg | 42 +++++++++ 12 files changed, 403 insertions(+), 5 deletions(-) create mode 100644 public/assets/images/lights/a19.svg create mode 100644 public/assets/images/lights/br30.svg create mode 100644 public/assets/images/lights/gu10.svg create mode 100644 public/assets/images/lights/huego.svg create mode 100644 public/assets/images/lights/lc_aura.svg create mode 100644 public/assets/images/lights/lc_bloom.svg create mode 100644 public/assets/images/lights/lc_iris.svg create mode 100644 public/assets/images/lights/lightstrip.svg create mode 100644 public/assets/images/lights/storylight.svg diff --git a/app/components/bridge-controls.js b/app/components/bridge-controls.js index 5ba08e0..f4007e9 100644 --- a/app/components/bridge-controls.js +++ b/app/components/bridge-controls.js @@ -17,6 +17,7 @@ export default Em.Component.extend({ this.set('lightsDataIntervalHandle', setInterval(this.updateLightData.bind(this), 1000)); }, + // determines whether the lights are on/off for the lights switch lightsOn: function(){ var lightsData = this.get('lightsData'); @@ -31,19 +32,88 @@ export default Em.Component.extend({ return false; }.property('lightsData'), + // determines the average brightness of the hue system for the brightness slider + lightsBrightness: function(){ + var lightsData = this.get('lightsData'), lightsBrightness = 0; + + for (var key in lightsData) { + if (lightsData.hasOwnProperty(key)) { + lightsBrightness += lightsData[key].state.bri; + } + } + + return lightsBrightness/this.get('lightsList').length; + }.property('lightsData', 'lightsList'), + + // list of all the lights in the hue system + lightsList: function(){ + var lightsData = this.get('lightsData'), lightsList = []; + for (var key in lightsData) { + if (lightsData.hasOwnProperty(key)) { + switch(lightsData[key].modelid){ + case 'LCT001': + lightsList.push('a19'); + break; + case 'LCT002': + lightsList.push('br30'); + break; + case 'LCT003': + lightsList.push('gu10'); + break; + case 'LST001': + lightsList.push('lightstrip'); + break; + case 'LLC010': + lightsList.push('lc_iris'); + break; + case 'LLC011': + lightsList.push('lc_bloom'); + break; + case 'LLC012': + lightsList.push('lc_bloom'); + break; + case 'LLC006': + lightsList.push('lc_iris'); + break; + case 'LLC007': + lightsList.push('lc_aura'); + break; + case 'LLC013': + lightsList.push('storylight'); + break; + case 'LWB004': + lightsList.push('a19'); + break; + case 'LLC020': + lightsList.push('huego'); + break; + default: + lightsList.push('a19'); + } + } + } + + return lightsList; + }.property('lightsData'), + + brightnessControlDisabled: function(){ + return !this.get('lightsOn'); + }.property('lightsOn'), + onLightsOnChange: function(){ - var lightsData = this.get('lightsData'), lightsOnState = false, lightsOn = this.get('lightsOn'); + var lightsData = this.get('lightsData'), lightsOnSystem = false, lightsOn = this.get('lightsOn'); for (let key in lightsData) { if (lightsData.hasOwnProperty(key)) { if(lightsData[key].state.on){ - lightsOnState = true; + lightsOnSystem = true; break; } } } - if(lightsOn !== lightsOnState){ + // if the internal lights state is different than the one from lightsData ( user manually toggled the switch ), send the request to change the bulbs state + if(lightsOn !== lightsOnSystem){ for (let key in lightsData) { Em.$.ajax(this.get('lightsApiURL') + '/' + key + '/state', { data: JSON.stringify({"on": lightsOn}), @@ -54,6 +124,28 @@ export default Em.Component.extend({ } }.observes('lightsOn'), + onBrightnessChange: function(){ + var lightsData = this.get('lightsData'), lightsBrightnessSystem = false, lightsBrightness = this.get('lightsBrightness'); + + for (let key in lightsData) { + if (lightsData.hasOwnProperty(key)) { + lightsBrightnessSystem += lightsData[key].state.bri; + } + } + lightsBrightnessSystem /= this.get('lightsList').length; + + // if the internal lights state is different than the one from lightsData ( user manually toggled the switch ), send the request to change the bulbs state + if(lightsBrightness !== lightsBrightnessSystem){ + for (let key in lightsData) { + Em.$.ajax(this.get('lightsApiURL') + '/' + key + '/state', { + data: JSON.stringify({"bri": lightsBrightness}), + contentType: 'application/json', + type: 'PUT' + }) + } + } + }.observes('lightsBrightness'), + lightsOnTxt: function(){ return this.get('lightsOn') ? 'On' : 'Off'; }.property('lightsOn'), diff --git a/app/templates/components/bridge-controls.hbs b/app/templates/components/bridge-controls.hbs index 025b568..1625fa6 100644 --- a/app/templates/components/bridge-controls.hbs +++ b/app/templates/components/bridge-controls.hbs @@ -1,5 +1,10 @@ + +{{#each lightsList as |light|}} + +{{/each}} +
Lights:
{{#paper-switch checked=lightsOn}} {{lightsOnTxt}} {{/paper-switch}}
Brightness:
-{{paper-slider flex=true min='0' max='255' value=lightsBrightness}} +{{paper-slider flex=true min='1' max='254' value=lightsBrightness disabled=brightnessControlDisabled}} diff --git a/config/environment.js b/config/environment.js index dd06d31..cab8549 100644 --- a/config/environment.js +++ b/config/environment.js @@ -25,7 +25,9 @@ module.exports = function(environment) { 'connect-src': "'self' *", 'img-src': "'self' data:", 'media-src': "'self'", - 'style-src': "'self' 'unsafe-inline'" + 'style-src': "'self' 'unsafe-inline'", + 'object-src': "'self'", + 'frame-src': "'self'" } }; diff --git a/public/assets/images/lights/a19.svg b/public/assets/images/lights/a19.svg new file mode 100644 index 0000000..cf3eee3 --- /dev/null +++ b/public/assets/images/lights/a19.svg @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/public/assets/images/lights/br30.svg b/public/assets/images/lights/br30.svg new file mode 100644 index 0000000..7d71208 --- /dev/null +++ b/public/assets/images/lights/br30.svg @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/assets/images/lights/gu10.svg b/public/assets/images/lights/gu10.svg new file mode 100644 index 0000000..014d2f5 --- /dev/null +++ b/public/assets/images/lights/gu10.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + diff --git a/public/assets/images/lights/huego.svg b/public/assets/images/lights/huego.svg new file mode 100644 index 0000000..e912e5a --- /dev/null +++ b/public/assets/images/lights/huego.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + diff --git a/public/assets/images/lights/lc_aura.svg b/public/assets/images/lights/lc_aura.svg new file mode 100644 index 0000000..9faf3b9 --- /dev/null +++ b/public/assets/images/lights/lc_aura.svg @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + diff --git a/public/assets/images/lights/lc_bloom.svg b/public/assets/images/lights/lc_bloom.svg new file mode 100644 index 0000000..a498b9a --- /dev/null +++ b/public/assets/images/lights/lc_bloom.svg @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + diff --git a/public/assets/images/lights/lc_iris.svg b/public/assets/images/lights/lc_iris.svg new file mode 100644 index 0000000..876b3d2 --- /dev/null +++ b/public/assets/images/lights/lc_iris.svg @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + diff --git a/public/assets/images/lights/lightstrip.svg b/public/assets/images/lights/lightstrip.svg new file mode 100644 index 0000000..1d55b8e --- /dev/null +++ b/public/assets/images/lights/lightstrip.svg @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/assets/images/lights/storylight.svg b/public/assets/images/lights/storylight.svg new file mode 100644 index 0000000..d04a5db --- /dev/null +++ b/public/assets/images/lights/storylight.svg @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + +