DurgNomis-drol / mytoyota

Python client for Toyota Connected Services API
MIT License
81 stars 33 forks source link

Fix wrong `fuel_consumed` conversion and add `average_fuel_consumed` #288

Closed CM000n closed 10 months ago

CM000n commented 10 months ago

Fix for: https://github.com/DurgNomis-drol/mytoyota/issues/287

The metric was converted from a bool to a string when the self variables was declared. This meant that simple conditions such as if self._metric no longer worked and the conversion of the fuel consumption failed, or rather the value for gallons was always returned. self._metric is now a bool again and a new variable self._distance_unit was introduced, which is used for the conversion of distances.

codecov[bot] commented 10 months ago

Codecov Report

Attention: 18 lines in your changes are missing coverage. Please review.

Comparison is base (66ad51e) 72.36% compared to head (0373179) 71.92%.

Files Patch % Lines
mytoyota/models/summary.py 10.00% 18 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #288 +/- ## ========================================== - Coverage 72.36% 71.92% -0.44% ========================================== Files 28 28 Lines 1357 1368 +11 ========================================== + Hits 982 984 +2 - Misses 375 384 +9 ``` | [Flag](https://app.codecov.io/gh/DurgNomis-drol/mytoyota/pull/288/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Simon+Hansen) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/DurgNomis-drol/mytoyota/pull/288/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Simon+Hansen) | `71.92% <10.00%> (-0.44%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Simon+Hansen#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

CM000n commented 10 months ago

During testing, I came across another problem. For example, a monthly statistic for December 2023 returns the following values

pp.pprint(
            f"Summary: {[[x] for x in await car.get_summary(date(2023, 12, 1), date(2023, 12, 31), summary_type=SummaryType.MONTHLY)]}"  # noqa: E501
        )
("Summary: [[average_speed=41.09 countries=['DE'] duration=16:52:14 "
 'distance=693.167 ev_duration=5:34:22 ev_distance=197.999 '
 'from_date=2023-12-01 to_date=2023-12-31 fuel_consumed=44.157]]')

But I definitely didn't consume 44 litres per 100 km 🤯 The app also shows me a more realistic 6.4l/100km. So it seems to calculate the values differently somehow.

This is not directly due to a problem with the conversion or processing of the values, as 44157.0 ml are also returned in the original _SummaryBaseModel used:

{
  "length": 693167,
  "duration": 60734,
  "duration_idle": 2125,
  "countries": [
    "DE"
  ],
  "max_speed": 132.0,
  "average_speed": 41.09,
  "length_overspeed": 66006,
  "duration_overspeed": 3493,
  "length_highway": 59361,
  "duration_highway": 2255,
  "fuel_consumption": 44157.0
}

.::edit::. It seems to be calculated by length and fuel_consumption:

(44157.0 / 693167)  * 100
>> 6.370326342713948