diff --git a/lib/HueBridge.js b/lib/HueBridge.js index 2277db02..c32dd17e 100644 --- a/lib/HueBridge.js +++ b/lib/HueBridge.js @@ -184,6 +184,7 @@ HueBridge.prototype.accessories = function() { this.accessoryList.push(this); }.bind(this)) .then(this.createUser.bind(this)) + .then(this.getBlacklist.bind(this)) .then(this.createGroup0.bind(this)) .then(this.createResources.bind(this)) .catch(function(err) { @@ -211,6 +212,38 @@ HueBridge.prototype.getConfig = function() { return d.promise; }; +HueBridge.prototype.getBlacklist = function() { + const d = deferred(); + + this.blacklist = { + sensors: [], + lights: [], + groups: [], + schedules: [], + rules: [] + }; + this.request('get', '/resourcelinks').then(function(obj) { + for (const key in obj) { + const link = obj[key]; + if (link.name === 'homebridge-hue' && link.links) { + this.log.debug( + '%s: /resourcelinks/%d: %d blacklist entries', this.name, + key, link.links.length + ); + for (const resource of link.links) { + const type = resource.split('/')[1]; + const id = resource.split('/')[2]; + if (this.blacklist[type]) { + this.blacklist[type][id] = true; + } + } + } + } + d.resolve(true); + }.bind(this)); + return d.promise; +} + HueBridge.prototype.createUser = function() { if (this.username) { this.url += '/' + this.username; @@ -262,7 +295,9 @@ HueBridge.prototype.createResources = function() { if (lightObj.manufacturer) { lightObj.manufacturername = lightObj.manufacturer; } - if ( + if (this.blacklist.lights[id]) { + this.log.debug('%s: /lights/%d: blacklisted', this.name, id); + } else if ( this.platform.config.philipsLights || lightObj.manufacturername !== 'Philips' ) { @@ -295,7 +330,9 @@ HueBridge.prototype.createResources = function() { if (this.platform.config.groups) { for (const id in obj.groups) { const group = obj.groups[id]; - if (this.platform.config.rooms || group.type !== 'Room') { + if (this.blacklist.groups[id]) { + this.log.debug('%s: /groups/%d: blacklisted', this.name, id); + } else if (this.platform.config.rooms || group.type !== 'Room') { this.log.debug( '%s: /groups/%d: %s "%s"', this.name, id, group.type, group.name ); @@ -314,7 +351,9 @@ HueBridge.prototype.createResources = function() { if (this.platform.config.sensors) { for (const id in obj.sensors) { const sensorObj = obj.sensors[id]; - if (this.platform.config.excludeSensorTypes[sensorObj.type] || + if (this.blacklist.sensors[id]) { + this.log.debug('%s: /sensors/%d: blacklisted', this.name, id); + } else if (this.platform.config.excludeSensorTypes[sensorObj.type] || (sensorObj.type.substring(0, 4) === 'CLIP' && this.platform.config.excludeSensorTypes.CLIP)) { this.log.debug( @@ -361,14 +400,18 @@ HueBridge.prototype.createResources = function() { this.log.debug('%s: %d sensors', this.name, this.state.sensors); if (this.platform.config.schedules) { for (const id in obj.schedules) { - const schedule = obj.schedules[id]; - this.log.debug( - '%s: /schedules/%d: "%s"', this.name, id, schedule.name - ); - this.schedules[id] = new HueSchedule(this, id, schedule); - // this.accessoryList.push(this.schedules[id]); - if (this.serviceList.length < 99) { - this.serviceList.push(this.schedules[id].service); + if (this.blacklist.schedules[id]) { + this.log.debug('%s: /schedules/%d: blacklisted', this.name, id); + } else { + const schedule = obj.schedules[id]; + this.log.debug( + '%s: /schedules/%d: "%s"', this.name, id, schedule.name + ); + this.schedules[id] = new HueSchedule(this, id, schedule); + // this.accessoryList.push(this.schedules[id]); + if (this.serviceList.length < 99) { + this.serviceList.push(this.schedules[id].service); + } } } this.state.schedules = Object.keys(this.schedules).length; @@ -376,12 +419,16 @@ HueBridge.prototype.createResources = function() { this.log.debug('%s: %d schedules', this.name, this.state.schedules); if (this.platform.config.rules) { for (const id in obj.rules) { - const rule = obj.rules[id]; - this.log.debug('%s: /rules/%d: "%s"', this.name, id, rule.name); - this.rules[id] = new HueSchedule(this, id, rule, 'rule'); - // this.accessoryList.push(this.rules[id]); - if (this.serviceList.length < 99) { - this.serviceList.push(this.rules[id].service); + if (this.blacklist.rules[id]) { + this.log.debug('%s: /rules/%d: blacklisted', this.name, id); + } else { + const rule = obj.rules[id]; + this.log.debug('%s: /rules/%d: "%s"', this.name, id, rule.name); + this.rules[id] = new HueSchedule(this, id, rule, 'rule'); + // this.accessoryList.push(this.rules[id]); + if (this.serviceList.length < 99) { + this.serviceList.push(this.rules[id].service); + } } } this.state.rules = Object.keys(this.rules).length;