diff --git a/src/index.js b/src/index.js index aa807d28050b08622117f5a99bda14b56a7322ec..c8a42057bbbd8f2746768218dc44e5236bccbcfa 100644 --- a/src/index.js +++ b/src/index.js @@ -47,8 +47,6 @@ async function start(fields, cozyParameters) { // await resetData() const baseUrl = cozyParameters.secret.eglBaseURL const apiAuthKey = cozyParameters.secret.eglAPIAuthKey - log('info', 'Start fields are : ' + fields) - log('info', 'Authenticating ...') const response = await authenticate( fields.login, @@ -150,12 +148,23 @@ async function getData(response, baseUrl, apiAuthKey) { } function format(response) { - const data = response.resultatRetour.slice(1).map((value, index) => { + const data = response.resultatRetour.slice(1).filter(value => { + value.TypeAgregat === "R" + }).map((value, index) => { const time = moment(value.DateReleve, moment.ISO_8601) - log('info', 'SUBSTRACTING : ' + value.ValeurIndex + ' - ' + response.resultatRetour[index].ValeurIndex + '\n') + log( + 'info', + 'date -> ' + value.DateReleve + ' SUBSTRACTING : ' + + value.ValeurIndex + + ' - ' + + response.resultatRetour[index].ValeurIndex + + '\n' + ) return { - // Add if/else to not substract null value (typeagregat T) - load: value.TypeAgregat === 'T' ? null : value.ValeurIndex - response.resultatRetour[index].ValeurIndex, + load: + value.TypeAgregat === 'T' + ? null + : value.ValeurIndex - response.resultatRetour[index].ValeurIndex, year: parseInt(time.format('YYYY')), month: parseInt(time.format('M')), day: parseInt(time.format('D')), @@ -165,8 +174,18 @@ function format(response) { } }) log('info', 'DATALOAD LIST\n') - data.map((value) => { - log('info', value.month + '-' + value.day + '-' + value.year + ' : ' + value.load + '\n') + data.map(value => { + log( + 'info', + value.month + + '-' + + value.day + + '-' + + value.year + + ' : ' + + value.load + + '\n' + ) }) return data }