const GSI_DGY = require("gsi-discovergy");
if((typeof process.env.DISCOVERGY_PASSWORD == "undefined")||(process.env.DISCOVERGY_PASSWORD == null)) {
process.env.DISCOVERGY_PASSWORD="demo";
}
if((typeof process.env.DISCOVERGY_ACCOUNT == "undefined")||(process.env.DISCOVERGY_ACCOUNT == null)) {
process.env.DISCOVERGY_ACCOUNT ="demo@discovergy.com";
}
exports.endpoint = function(request, response) {
let query = require('url').parse(request.url,true).query;
let res = [];
let instance = new GSI_DGY({DISCOVERGY_PASSWORD:process.env.DISCOVERGY_PASSWORD,DISCOVERGY_ACCOUNT:process.env.DISCOVERGY_ACCOUNT});
instance.meters().then(function(meters) {
for(let j=0 ; j<meters.length ; j++) {
if(typeof meters[j].account != "undefined") {
let item = {};
item.serialNumber = meters[j].serialNumber;
item.location = meters[j].location.city;
item.oracle = meters[j].account;
item.co2_g_standard = meters[j].co2_g_standard;
item.co2_g_oekostrom = meters[j].co2_g_oekostrom;
res.push(item);
}
}
response.end(JSON.stringify(res));
});
}