Skip to content

Commit 9fcf65c

Browse files
committed
Fixed ETA
1 parent 1e42af3 commit 9fcf65c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/tesla_client.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ void TeslaClient::requestChargeState()
423423

424424
evse.setVehicleStateOfCharge(_chargeInfo.batteryLevel);
425425
evse.setVehicleRange(_chargeInfo.batteryRange);
426-
evse.setVehicleEta(_chargeInfo.timeToFullCharge);
426+
evse.setVehicleEta(_hoursToSeconds(_chargeInfo.timeToFullCharge));
427427

428428
DynamicJsonDocument data(4096);
429429
getChargeInfoJson(data);
@@ -455,8 +455,16 @@ void TeslaClient::getChargeInfoJson(JsonDocument &doc)
455455
doc["charge_energy_added"] = _chargeInfo.chargeEnergyAdded;
456456
doc["charge_miles_added_rated"] = _chargeInfo.chargeMilesAddedRated;
457457
doc["charge_limit_soc"] = _chargeInfo.chargeLimitSOC;
458-
doc["time_to_full_charge"] = _chargeInfo.timeToFullCharge;
458+
doc["time_to_full_charge"] = _hoursToSeconds(_chargeInfo.timeToFullCharge);
459459
doc["charger_voltage"] = _chargeInfo.chargerVoltage;
460460
doc["tesla_error"] = false;
461461
}
462462
}
463+
464+
int TeslaClient::_hoursToSeconds(float hours)
465+
{
466+
// time_to_full_charge is in hours (float) with ~5min intervals, needs to be seconds for
467+
// our internal representation
468+
int minutes = (int)round(60.0 * hours);
469+
return minutes * 60;
470+
}

src/tesla_client.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ typedef struct telsa_charge_info {
2727
float chargeMilesAddedRated;
2828
int batteryLevel;
2929
int chargeLimitSOC;
30-
int timeToFullCharge;
30+
float timeToFullCharge;
3131
int chargerVoltage;
3232
} TESLA_CHARGE_INFO;
3333

@@ -58,6 +58,7 @@ class TeslaClient {
5858

5959
bool _isBusy() { return _activeRequest == TAR_NONE ? false : true; }
6060
void _cleanVehicles();
61+
int _hoursToSeconds(float hours);
6162

6263
public:
6364
TeslaClient();

0 commit comments

Comments
 (0)