ilcato / homebridge-Fibaro-HC2

Homebridge plugin for Fibaro Home Center 2 (and Home Center Lite ...)
Apache License 2.0
65 stars 27 forks source link

Homebridge crashes with error referencing promise #16

Closed bossabode closed 8 years ago

bossabode commented 8 years ago

Hey Guys,

Hope you can help with this one as I've gotten a little bit stuck.

Home bridge starts then crashes on errors referencing promise.

screen shot 2016-07-19 at 2 36 17 pm
bossabode commented 8 years ago

The referenced figaro-api.js file is as below.

`// Fibaro rest api client

'use strict';

var request = require("request");

function FibaroClient(host, username, password) { this.host = "192.168.105.4"; this.username = "admin"; this.password = "admin"; this.auth = "Basic " + new Buffer(this.username + ":" + this.password).toString("base64"); } FibaroClient.prototype.getRooms = function() { var that = this; var p = new Promise(function(resolve, reject) { var url = "http://"+that.host+"/api/rooms"; request.get({ url: url, headers : { "Authorization" : that.auth }, json: true }, function(err, response, json) { if (!err && response.statusCode == 200) resolve(json); else reject(err, response); }); }); return p; } FibaroClient.prototype.getDevices = function() { var that = this; var p = new Promise(function(resolve, reject) { var url = "http://"+that.host+"/api/devices"; request.get({ url: url, headers : { "Authorization" : that.auth }, json: true }, function(err, response, json) { if (!err && response.statusCode == 200) resolve(json); else reject(err, response); }); }); return p; } FibaroClient.prototype.getDeviceProperties = function(ID) { var that = this; var p = new Promise(function(resolve, reject) { var url = "http://"+that.host+"/api/devices/"+ID; request.get({ url: url, headers : { "Authorization" : that.auth }, json: true }, function(err, response, json) { if (!err && response.statusCode == 200) resolve(json.properties); else reject(err, response); }); }); return p; } FibaroClient.prototype.executeDeviceAction = function(ID, action, param) { var that = this; var p = new Promise(function(resolve, reject) { var url = "http://"+that.host+"/api/devices/"+ID+"/action/"+action; var body = param != undefined ? JSON.stringify({ "args": [ param ] }) : null; var method = "post"; request({ url: url, body: body, method: method, headers: { "Authorization" : that.auth } }, function(err, response) { if (!err && (response.statusCode == 200 || response.statusCode == 202)) resolve(response); else reject(err, response); }); }); return p; } FibaroClient.prototype.refreshStates = function(lastPoll) { var that = this; var p = new Promise(function(resolve, reject) { var url = "http://"+that.host +"/api/refreshStates?last=" + lastPoll; request.get({ url: url, headers : { "Authorization" : that.auth }, json: true }, function(err, response, json) { if (!err && response.statusCode == 200) resolve(json); else reject(err, response); }); }); return p; }

module.exports.createClient = function(host, username, password) { return new FibaroClient(host, username, password); } `

ilcato commented 8 years ago

which version of node.js do you have?

bossabode commented 8 years ago

Thanks for such a quick response ilcato

Node version is v0.10.46

ilcato commented 8 years ago

You need a node version 4.0 or up.