Skip to content

Commit

Permalink
Blacklist for resources (#170).
Browse files Browse the repository at this point in the history
Any resource link named `homebridge-hue` is treated as a blacklist for
resources.  Resources in these resource links are not exposed to
HomeKit, regardless of the config.json settings.
  • Loading branch information
ebaauw committed Oct 21, 2017
1 parent 6756e25 commit b156a68
Showing 1 changed file with 64 additions and 17 deletions.
81 changes: 64 additions & 17 deletions lib/HueBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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'
) {
Expand Down Expand Up @@ -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
);
Expand All @@ -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(
Expand Down Expand Up @@ -361,27 +400,35 @@ 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;
}
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;
Expand Down

0 comments on commit b156a68

Please sign in to comment.