Merge pull request #14031 from hallard/teleinfo_fix_total

Teleinfo : Fix some calculation
This commit is contained in:
Theo Arends 2022-01-09 21:11:53 +01:00 committed by GitHub
commit f1bb492209
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 25 deletions

View File

@ -333,56 +333,55 @@ void DataCallback(struct _ValueList * me, uint8_t flags)
// Base, un seul index // Base, un seul index
if (ilabel == LABEL_BASE) { if (ilabel == LABEL_BASE) {
total = atoi(me->value); total = atol(me->value);
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: Base:%u"), total); AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: Base:%ld"), total);
// Heures creuses/pleines calculer total // Heures creuses/pleines calculer total
} else { } else {
// Heures creuses get heures pleines // Heures creuses get heures pleines
if (ilabel == LABEL_HCHC) { if (ilabel == LABEL_HCHC) {
hc = atoi(me->value); hc = atol(me->value);
if ( getValueFromLabelIndex(LABEL_HCHP, value) ) { if ( getValueFromLabelIndex(LABEL_HCHP, value) ) {
hp = atoi(value); hp = atol(value) ;
} }
// Heures pleines, get heures creuses // Heures pleines, get heures creuses
} else if (ilabel == LABEL_HCHP) { } else if (ilabel == LABEL_HCHP) {
hp = atoi(me->value); hp = atol(me->value);
if ( getValueFromLabelIndex(LABEL_HCHC, value) ) { if ( getValueFromLabelIndex(LABEL_HCHC, value) ) {
hc = atoi(value); hc = atol(value) ;
} }
} }
total = hc + hp; if (hc>0 && hp>0) {
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: HC:%u HP:%u Total:%u"), hc, hp, total); total = hc + hp;
}
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: HC:%ld HP:%ld Total:%ld"), hc, hp, total);
} }
Energy.import_active[0] = total/1000.0f; AddLog (LOG_LEVEL_INFO, PSTR ("TIC: Total counter updated to %ld Wh"), total);
EnergyUpdateTotal(); if (total>0) {
AddLog (LOG_LEVEL_INFO, PSTR ("TIC: Total counter updated to %u Wh"), total); Energy.import_active[0] = (float)total/1000.0f;
EnergyUpdateTotal();
AddLog (LOG_LEVEL_DEBUG_MORE, PSTR ("TIC: import_active[0]=%.3fKWh"), Energy.import_active[0] );
}
} }
// Wh total index (standard) // Wh total index (all contract)
else if ( ilabel == LABEL_EAST) else if ( ilabel == LABEL_EAST)
{ {
uint32_t total = atoi(me->value); uint32_t total = atol(me->value);
if (contrat != CONTRAT_BAS) { Energy.import_active[0] = (float)total/1000.0f;
Energy.import_active[0] = total/1000.0f; EnergyUpdateTotal();
EnergyUpdateTotal(); AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: Total:%ldWh"), total);
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: Total:%uWh"), total);
}
} }
// Wh indexes (standard) // Wh indexes (standard)
else if ( ilabel == LABEL_EASF01) else if ( ilabel == LABEL_EASF01)
{ {
if (contrat == CONTRAT_BAS) { AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: HC:%ld"), atol(me->value));
Energy.import_active[0] = atoi(me->value)/1000.0f;
EnergyUpdateTotal();
}
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: HC:%u"), atoi(me->value));
} }
else if ( ilabel == LABEL_EASF02) else if ( ilabel == LABEL_EASF02)
{ {
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: HP:%u"), atoi(me->value)); AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: HP:%ld"), atol(me->value));
} }
// Contract subscribed (legacy) // Contract subscribed (legacy)
@ -504,7 +503,7 @@ bool ResponseAppendTInfo(char sep, bool all)
if (!isNumber) { if (!isNumber) {
ResponseAppend_P( PSTR("\"%s\""), me->value ); ResponseAppend_P( PSTR("\"%s\""), me->value );
} else { } else {
ResponseAppend_P( PSTR("%d"), atoi(me->value)); ResponseAppend_P( PSTR("%ld"), atol(me->value));
} }
// Now JSON separator is needed // Now JSON separator is needed