This repository has been archived on 2026-04-30. You can view files and clone it, but cannot push or open issues or pull requests.
huegasm/web/app/pods/components/light-group/component.js
lone-cloud 40eb0cae00 removing groups, fixing deprecations, switching to paper's menu way
BUGS: error on bridge authentication, lightData not updating correctly to reflect the state, unstyled settings menu
2016-10-12 23:18:34 -07:00

134 lines
3.5 KiB
JavaScript

import Ember from 'ember';
const {
Component,
observer,
isEmpty,
$,
A
} = Ember;
export default Component.extend({
classNames: ['light-group'],
isHovering: false,
lightsList: A(),
// list of all the lights in the hue system
onLightsDataChange: observer('lightsData', 'activeLights.[]', 'dimmerOn', function(){
if(!this.get('isHovering')){
let lightsData = this.get('lightsData'),
lightsList = A(),
type;
for (let key in lightsData) {
if (lightsData.hasOwnProperty(key) && lightsData[key].state.reachable) {
switch(lightsData[key].modelid){
case 'LCT001':
type = 'a19';
break;
case 'LCT002':
type = 'br30';
break;
case 'LCT003':
type = 'gu10';
break;
case 'LST001':
type = 'lightstrip';
break;
case 'LLC010':
type = 'lc_iris';
break;
case 'LLC011':
type = 'lc_bloom';
break;
case 'LLC012':
type = 'lc_bloom';
break;
case 'LLC006':
type = 'lc_iris';
break;
case 'LLC007':
type = 'lc_aura';
break;
case 'LLC013':
type = 'storylight';
break;
case 'LWB004':
type ='a19';
break;
case 'LLC020':
type = 'huego';
break;
default:
type = 'a19';
}
let activeClass = 'light-active';
if(!this.get('activeLights').includes(key)){
activeClass = 'light-inactive';
}
lightsList.push({type: type, name: lightsData[key].name, id: key, data: lightsData[key], activeClass: activeClass});
}
}
this.set('lightsList', lightsList);
}
}),
didInsertElement() {
if(this.get('lightsData')){
this.onLightsDataChange();
}
},
actions: {
clickLight(id, data){
let light = $('.light'+id);
if(!light.hasClass('bootstrap-tooltip')){
light = light.parent();
}
if(light.hasClass('light-inactive')){
light.addClass('light-active').removeClass('light-inactive');
} else if(light.hasClass('light-active')){
light.addClass('light-inactive').removeClass('light-active');
}
this.sendAction('action', id, data);
},
lightStartHover(id){
let hoveredLight = this.get('lightsList').filter(function(light){
return light.activeClass !== 'unreachable' && light.id === id[0];
});
if(!isEmpty(hoveredLight) && this.get('noHover') !== true){
$.ajax(this.get('apiURL') + '/lights/' + id + '/state', {
data: JSON.stringify({"alert": "lselect"}),
contentType: 'application/json',
type: 'PUT'
});
}
this.set('isHovering', true);
},
lightStopHover(id){
let hoveredLight = this.get('lightsList').filter(function(light){
return light.activeClass !== 'unreachable' && light.id === id[0];
});
if(!isEmpty(hoveredLight) && this.get('noHover') !== true){
$.ajax(this.get('apiURL') + '/lights/' + id + '/state', {
data: JSON.stringify({"alert": "none"}),
contentType: 'application/json',
type: 'PUT'
});
}
this.set('isHovering', false);
this.onLightsDataChange();
}
}
});