audiconnect / audi_connect_ha

Adds an audi connect integration to home assistant
MIT License
227 stars 98 forks source link

fix: Trip Data #382

Closed coreywillwhat closed 5 months ago

coreywillwhat commented 5 months ago

Purpose

This PR brings functionality back to the short term and long term trip data sensors.

The Issue

The primary issue was the state of the sensor returning the full data for the relevant trip which exceeded 255 characters.

The Solution

State now displays the timestamp from the trip, and attributes have been added to the sensor for the other trip data. Using get with defaults to avoid keyerrors.

Testing

Tested with hardcoded values known to not be available. Tests show the code handled the keyerrors gracefully. Tested with None hardcoded as well and 'null' is properly reported.

Kolbi commented 5 months ago

ShortTerm is working for me, but do you see LongTerm entities?

Edit: Log:

2024-04-16 06:50:11.466 DEBUG (MainThread) [custom_components.audiconnect.audi_services] TRIP DATA: td_current: {'tripType': 'shortTerm', 'tripID': 123, 'averageElectricEngineConsumption': 123, 'averageFuelConsumption': 36, 'averageSpeed': 89, 'mileage': 81, 'startMileage': 20765, 'traveltime': 55, 'zeroEmissionDistance': 480, 'timestamp': datetime.datetime(2024, 4, 16, 4, 10, 43, tzinfo=datetime.timezone.utc), 'reportReason': 'clamp15off', 'overallMileage': 20846}
2024-04-16 06:50:11.466 DEBUG (MainThread) [custom_components.audiconnect.audi_services] TRIP DATA: td_reset_trip: {'tripType': 'shortTerm', 'tripID': 234, 'averageElectricEngineConsumption': 113, 'averageFuelConsumption': 34, 'averageSpeed': 63, 'mileage': 35, 'startMileage': 20729, 'traveltime': 33, 'zeroEmissionDistance': 202, 'timestamp': datetime.datetime(2024, 4, 15, 14, 49, 29, tzinfo=datetime.timezone.utc), 'reportReason': 'clamp15off', 'overallMileage': 20765}
2024-04-16 06:50:11.577 DEBUG (MainThread) [custom_components.audiconnect.audi_services] TRIP DATA: td_current: {'tripType': 'longTerm', 'tripID': 345, 'averageElectricEngineConsumption': 132, 'averageFuelConsumption': 42, 'averageSpeed': 58, 'mileage': 20846, 'startMileage': 0, 'traveltime': 21450, 'zeroEmissionDistance': 35793, 'timestamp': datetime.datetime(2024, 4, 16, 4, 10, 43, tzinfo=datetime.timezone.utc), 'reportReason': 'clamp15off', 'overallMileage': 20846}
coreywillwhat commented 5 months ago

@Kolbi @cdnninja I've converted this to a draft due to @Kolbi 's issue with long term trip data. If changing that line back resolves it. Please feel free to move it back to ready for review, update the PR with that line change and merge it. I probably won't be as active in the coming days/weeks.

Kolbi commented 5 months ago

Working now. Merged PR.