Newer
Older
// @ts-check
const { log } = require('cozy-konnector-libs')
/**
* Return User PDL
* @param {string} result
* @returns {string}
*/
function parseUserPdl(result) {
log('info', 'Parsing User Pdl')
const json = JSON.stringify(result)
return JSON.parse(json)['Envelope']['Body']['rechercherPointResponse'][
'points'
]['point']['$'].id
}

Bastien DUMONT
committed
* Return User contract start date
* @param {string} result
* @returns {string}
*/

Bastien DUMONT
committed
function parseContractStartDate(result) {
log('info', 'Parsing contract start date')
return JSON.parse(json)['Envelope']['Body'][
'consulterDonneesTechniquesContractuellesResponse'
]['point']['donneesGenerales'][
'dateDerniereModificationFormuleTarifaireAcheminement'
]
}

Bastien DUMONT
committed
/**
* Return User contract start date
* @param {string} result
* @returns {Contract[] | Contract}
*/
function parseContracts(result) {
log('info', 'Parsing contract')
const json = JSON.stringify(result)
return JSON.parse(json)['Envelope']['Body'][
'rechercherServicesSouscritsMesuresResponse'
]['servicesSouscritsMesures']['serviceSouscritMesures']
}
/**
* Return User contract start date
* @param {string} result
* @returns {number}
*/
function parseServiceId(result) {
log('info', 'Parsing serviceId')
const json = JSON.stringify(result)
return JSON.parse(json)['Envelope']['Body'][
'commanderCollectePublicationMesuresResponse'
]['serviceSouscritId']
}
* @param {string} result
* @returns {SGEData[]}
*/
function parseSgeXmlData(result) {
log('info', 'Parsing list of documents')
return JSON.parse(json)['Envelope']['Body'][
'consulterMesuresDetailleesResponse'
]['grandeur']['mesure']
}
/**
* Format data for DB storage
* @param {SGEData[]} data
* @returns {Promise<EnedisKonnectorData[]>} Parsed timestamp array
*/
async function formateDataForDoctype(data) {
log('info', 'Formating data')
return data.map(record => {
const date = moment(record.d, 'YYYY/MM/DD h:mm:ss')
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
return {
load: record.v,
year: parseInt(date.format('YYYY')),
month: parseInt(date.format('M')),
day: parseInt(date.format('D')),
hour: parseInt(date.format('H')),
minute: parseInt(date.format('m')),
}
})
}
/**
* Format tag in order to be manipulated easly
* @param {string} name
* @returns {string} name
*/
function parseTags(name) {
if (name.split(':')[1] !== undefined) {
return name.split(':')[1]
}
return name
}
/**
*
* @param {string} value
* @param {string} name
* @returns {string|number} value
*/
function parseValue(value, name) {
// Wh => KWh
if (name === 'v') {
return parseFloat((parseInt(value) / 1000).toFixed(2))
}
return value
}

Bastien DUMONT
committed
parseContracts,
parseContractStartDate,
parseServiceId,