diff --git a/index.js b/index.js index 35302e3b372ae6ed65f8aa0ab58ab436f8e15da7..a748668444324ed20595e315afd67a2acc487dd0 100644 --- a/index.js +++ b/index.js @@ -21,6 +21,7 @@ const { formateDataForDoctype, parseTags, parseValue, + parseValueHalfHour, } = __webpack_require__(1561) const { consultationMesuresDetailleesMaxPower, @@ -424,11 +425,9 @@ async function getDataHalfHour(url, apiAuthKey, userLogin, pointId) { apikey: apiAuthKey, } - let MAX_HISTO = 4 - // If manual execution, retrieve only 1 week - if (manualExecution) { - MAX_HISTO = 1 - } + // If manual execution, retrieve only 1 week otherwise retrieve 4 weeks + const MAX_HISTO = manualExecution ? 1 : 4 + for (var i = 0; i < MAX_HISTO; i++) { log('info', 'launch process with history') const increamentedStartDateString = moment(startLoadDate) @@ -459,7 +458,7 @@ async function getDataHalfHour(url, apiAuthKey, userLogin, pointId) { response.body, { tagNameProcessors: [parseTags], - valueProcessors: [parseValue], + valueProcessors: [parseValueHalfHour], explicitArray: false, }, processData('com.grandlyon.enedis.minute') @@ -223777,6 +223776,20 @@ function parseValue(value, name) { return value } +/** + * + * @param {string} value + * @param {string} name + * @returns {string|number} value + */ +function parseValueHalfHour(value, name) { + // W * 1/2h => KW * h + if (name === 'v') { + return parseFloat((parseInt(value) / 2000).toFixed(2)) + } + return value +} + /** * Remove SGE useless multiple white spaces * @param {string} str @@ -223796,18 +223809,19 @@ function removeAddressnumber(str) { } module.exports = { - parseSgeXmlData, + checkContractExists, formateDataForDoctype, - parseTags, - parseValue, - parseUserPdl, parseContracts, parseContractStartDate, parseServiceId, + parseSgeXmlData, + parseTags, parseUserAddress, - checkContractExists, - removeMultipleSpaces, + parseUserPdl, + parseValue, + parseValueHalfHour, removeAddressnumber, + removeMultipleSpaces, } @@ -228510,6 +228524,10 @@ async function verifyContract(url, apiAuthKey, appLogin, contractId, pointId) { `Enedis issue ${parsedReply.Envelope.Body.Fault.detail.erreur.resultat.$.code}: ${parsedReply.Envelope.Body.Fault.faultstring}` ) } + log( + 'error', + 'if an erorr is thrown here, it probably means that the contract has already been open today and that enedis cannot open a second one. Wait until tomorow to try again' + ) throw errors.LOGIN_FAILED } } diff --git a/onDeleteAccount.js b/onDeleteAccount.js index 9a2e20feb49dfff55cf091a072272d37958834a2..8bb3ac2eca329f4515fd4aa1f8b7d34d2055dc73 100644 --- a/onDeleteAccount.js +++ b/onDeleteAccount.js @@ -223097,6 +223097,20 @@ function parseValue(value, name) { return value } +/** + * + * @param {string} value + * @param {string} name + * @returns {string|number} value + */ +function parseValueHalfHour(value, name) { + // W * 1/2h => KW * h + if (name === 'v') { + return parseFloat((parseInt(value) / 2000).toFixed(2)) + } + return value +} + /** * Remove SGE useless multiple white spaces * @param {string} str @@ -223116,18 +223130,19 @@ function removeAddressnumber(str) { } module.exports = { - parseSgeXmlData, + checkContractExists, formateDataForDoctype, - parseTags, - parseValue, - parseUserPdl, parseContracts, parseContractStartDate, parseServiceId, + parseSgeXmlData, + parseTags, parseUserAddress, - checkContractExists, - removeMultipleSpaces, + parseUserPdl, + parseValue, + parseValueHalfHour, removeAddressnumber, + removeMultipleSpaces, }