Skip to content

Commit

Permalink
updates to merge user_data
Browse files Browse the repository at this point in the history
  • Loading branch information
drewcovi committed Mar 12, 2017
1 parent 455669b commit bc5f404
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ VeraLinkPlatform.prototype = {
.getVeraInfo()
.then( (verainfo)=>{
if(typeof verainfo === 'object'){
var devices = this.functions.processall(this.verainfo);
var devices = this.functions.processall(verainfo);
var accessories = devices.map( (device)=>{
return this.createAccessory(device,this);
});
Expand Down
36 changes: 26 additions & 10 deletions lib/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,27 @@ module.exports = function(HAPnode, config)

module.getVeraInfo = function()
{
var url = "http://" + config.veraIP + ":3480/data_request?id=user_data";
return HAPnode.
request({
return HAPnode
.request({
method: 'GET',
uri: url,
uri: "http://" + config.veraIP + ":3480/data_request?id=user_data",
json: true
}).then(function (data) {
}).then( (data)=> {
return HAPnode
.request({
method: 'GET',
uri: "http://" + config.veraIP + ":3480/data_request?id=lu_sdata",
json: true
}).then( (response)=>{
data.devices.forEach( (device, index)=>{
var match = response.devices.find( (sdevice, index)=>{
return parseInt(device.id) === parseInt(sdevice.id);
})
Object.assign(device, match);
});
return data;
});
}).then( function(data){
devices = {};
if(typeof data === 'object'){
data.devices.forEach(function(device)
Expand All @@ -49,7 +63,6 @@ module.exports = function(HAPnode, config)

devices[device.room].push(device);
});

return(
{
rooms: data.rooms,
Expand All @@ -62,9 +75,9 @@ module.exports = function(HAPnode, config)
} else {
return(null);
}
}.bind(this)).catch(function (err) {
HAPnode.debug("Request error:"+err);
});
}.bind(this)).catch(function (err) {
HAPnode.debug("Request error:"+err);
});
},

module.processall = function(verainfo)
Expand Down Expand Up @@ -174,10 +187,13 @@ module.exports = function(HAPnode, config)
module.processdevices = function(list, verainfo)
{
var accessories = [];

list.forEach(function(device)
{
HAPnode.debug(device.name + ' ID:' +device.id);
device.category = device.category_num;
device.subcategory = device.subcategory_num;
delete device.category_num;
delete device.subcategory_num;
switch (device.category)
{
case 2: // Dimmable Light:
Expand Down
1 change: 0 additions & 1 deletion lib/types/sensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ module.exports = function (HAPnode, config, functions) {
module = {};

return function (device) {

var hapuuid = uuid.generate('device:sensor:' + config.cardinality + ':' + device.id),
accessory = new Accessory(device.name, hapuuid),
serviceMap = SensorMap.find(function(service, index){
Expand Down

0 comments on commit bc5f404

Please sign in to comment.