Skip to content

Commit

Permalink
deCONZ support
Browse files Browse the repository at this point in the history
Added description to http status error (e.g. “403 Forbidden” instead of
just “403”).

Added a number of hacks for deCONZ support (see issue #112):
- Use the username from `users[‘undefined’]` in `config.json` for
unauthenticated GET `/api/config`.
- Use `config.mac` when `config.bridgeid` is not available.
- UPnP discovery of deCONZ.
  • Loading branch information
ebaauw committed May 20, 2017
1 parent 41dadd5 commit d8fa068
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
12 changes: 7 additions & 5 deletions lib/HueBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ HueBridge.prototype.accessories = function() {
return this.getConfig()
.then(function(obj) {
this.name = obj.name;
this.uuid_base = obj.bridgeid;
this.uuid_base = obj.bridgeid || obj.mac;
this.username = this.platform.config.users[this.uuid_base] || '';
this.config = {
parallelRequests: 10,
Expand All @@ -98,8 +98,6 @@ HueBridge.prototype.accessories = function() {
break;
case undefined: // deCONZ rest api v2_04_40
obj.modelid = 'deCONZ'; // HACK
this.uuid_base = obj.mac; // HACK
this.username = this.platform.config.users[this.uuid_base] || '';
/* falls through */
case 'deCONZ': // deCONZ rest api
obj.manufacturername = 'dresden elektronik';
Expand Down Expand Up @@ -170,7 +168,10 @@ HueBridge.prototype.accessories = function() {
HueBridge.prototype.getConfig = function() {
const d = deferred();

this._request('get', '/config').then(function(obj) {
// this._request('get', '/config').then(function(obj) {
const username = this.platform.config.users['undefined']; // HACK
const path = (username || '') + '/config'; // HACK
this._request('get', path).then(function(obj) { // HACK
d.resolve(obj);
}.bind(this))
.catch(function (err) {
Expand Down Expand Up @@ -660,7 +661,8 @@ HueBridge.prototype._request = function(method, resource, body) {
if (response.statusCode != 200) {
this.log.error(requestMsg);
this.log.error(
'%s: hue bridge http status %s', this.name, response.statusCode
'%s: hue bridge http status %s %s', this.name,
response.statusCode, response.statusMessage
);
return d.reject(response.statusCode);
}
Expand Down
11 changes: 8 additions & 3 deletions lib/HuePlatform.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ function upnpParseMessage(message) {
const lines = message.toString().split('\r\n');
if (lines && lines[0]) {
obj.status = lines[0];
for (const line in lines) {
const fields = lines[line].split(': ');
for (const line of lines) {
const fields = line.split(': ');
if (fields.length === 2) {
obj[fields[0].toLowerCase()] = fields[1];
} else { // HACK
const fields = line.split(':'); // HACK
if (fields.length === 2) { // HACK
obj[fields[0].toLowerCase()] = fields[1]; // HACK
}
}
}
}
Expand Down Expand Up @@ -625,7 +630,7 @@ HuePlatform.prototype.upnpSearch = function() {
const response = upnpParseMessage(message);
if (
response.status === 'HTTP/1.1 200 OK' &&
response.st && response.st === 'upnp:rootdevice' &&
response.st && // response.st === 'upnp:rootdevice' && HACK
(response['hue-bridgeid'] || response['gwid.phoscon.de'])
) {
const ipaddress = rinfo.address;
Expand Down

0 comments on commit d8fa068

Please sign in to comment.