persist activelights

This commit is contained in:
Egor 2016-10-17 23:30:46 -07:00
parent f290dac941
commit b59957347e
2 changed files with 22 additions and 5 deletions

View file

@ -5,6 +5,8 @@ const {
Component, Component,
computed, computed,
isEmpty, isEmpty,
isNone,
observer,
$ $
} = Ember; } = Ember;
@ -83,15 +85,28 @@ export default Component.extend({
return lightsList; return lightsList;
}), }),
onActiveLightsChange: observer('activeLights.[]', function(){
this.get('storage').set('huegasm.activeLights', this.get('activeLights'));
}),
init(){ init(){
this._super(...arguments); this._super(...arguments);
let lightsData = this.get('lightsData'), 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(!isNone(activeLightsCache)){
if (lightsData.hasOwnProperty(key) && lightsData[key].state.reachable) { activeLightsCache.forEach(function(i){
activeLights.pushObject(key); 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);
}
} }
} }
}, },

View file

@ -34,7 +34,9 @@ export default Component.extend(helperMixin, visualizerMixin, {
}), }),
updatePageTitle: observer('playQueuePointer', function(){ 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){ if(playQueuePointer !== -1){
let song = playQueue[playQueuePointer]; let song = playQueue[playQueuePointer];