From 5121226a10a920e30c5383a62b7033b31bc00ca8 Mon Sep 17 00:00:00 2001 From: lone-cloud Date: Mon, 17 Oct 2016 23:30:46 -0700 Subject: [PATCH] persist activelights --- .../pods/components/light-group/component.js | 23 +++++++++++++++---- .../pods/components/music-tab/component.js | 4 +++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/web/app/pods/components/light-group/component.js b/web/app/pods/components/light-group/component.js index 21dc857..7b448bd 100644 --- a/web/app/pods/components/light-group/component.js +++ b/web/app/pods/components/light-group/component.js @@ -5,6 +5,8 @@ const { Component, computed, isEmpty, + isNone, + observer, $ } = Ember; @@ -83,15 +85,28 @@ export default Component.extend({ return lightsList; }), + onActiveLightsChange: observer('activeLights.[]', function(){ + this.get('storage').set('huegasm.activeLights', this.get('activeLights')); + }), + init(){ this._super(...arguments); let lightsData = this.get('lightsData'), - activeLights = this.get('activeLights'); + activeLights = this.get('activeLights'), + activeLightsCache = this.get('storage').get('huegasm.activeLights'); - for (let key in lightsData) { - if (lightsData.hasOwnProperty(key) && lightsData[key].state.reachable) { - activeLights.pushObject(key); + if(!isNone(activeLightsCache)){ + activeLightsCache.forEach(function(i){ + if (lightsData.hasOwnProperty(i) && lightsData[i].state.reachable) { + activeLights.pushObject(i); + } + }); + } else { + for (let key in lightsData) { + if (lightsData.hasOwnProperty(key) && lightsData[key].state.reachable) { + activeLights.pushObject(key); + } } } }, diff --git a/web/app/pods/components/music-tab/component.js b/web/app/pods/components/music-tab/component.js index d91d4cd..c4cf9ef 100644 --- a/web/app/pods/components/music-tab/component.js +++ b/web/app/pods/components/music-tab/component.js @@ -34,7 +34,9 @@ export default Component.extend(helperMixin, visualizerMixin, { }), updatePageTitle: observer('playQueuePointer', function(){ - let title = 'Huegasm', playQueuePointer = this.get('playQueuePointer'), playQueue = this.get('playQueue'); + let title = 'Huegasm', + playQueuePointer = this.get('playQueuePointer'), + playQueue = this.get('playQueue'); if(playQueuePointer !== -1){ let song = playQueue[playQueuePointer];