-
Notifications
You must be signed in to change notification settings - Fork 19
feat: Add EU tripinfo speed/duration fetching with local caching #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
cb19f51
50606b2
7ee6de3
2b5d206
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -328,4 +328,23 @@ public final class HyundaiEuropeAPIClient: APIClientBase, APIClientProtocol { | |
|
|
||
| return try parseEVTripDetailsResponse(data, vehicle: vehicle) | ||
| } | ||
|
|
||
| public func fetchEVTripInfo(for vehicle: Vehicle, authToken: AuthToken, dateString: String) async throws -> [EVTripInfo]? { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make the dateString an actual |
||
| let ccs2 = vehicle.marketOptions?.ccs2Supported ?? false | ||
| let url = "\(baseURL)/api/v1/spa/vehicles/\(vehicle.regId)/tripinfo" | ||
|
|
||
| let (data, _, _) = try await performJSONRequest( | ||
| url: url, | ||
| method: .POST, | ||
| headers: authorizedHeaders(authToken: authToken, ccs2: ccs2), | ||
| body: [ | ||
| "tripPeriodType": 1, | ||
| "setTripDay": dateString | ||
| ], | ||
| requestType: .fetchEVTripDetails, | ||
| vin: vehicle.vin | ||
| ) | ||
|
|
||
| return try parseIndividualTripsResponse(data) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,3 +103,26 @@ public struct EVTripDetailsResponse: Codable, Sendable { | |
| self.trips = trips | ||
| } | ||
| } | ||
|
|
||
| // MARK: - EV Trip Info | ||
|
|
||
| /// Represents summary of a specific trip from the tripinfo endpoint | ||
| public struct EVTripInfo: Codable, Hashable, Sendable { | ||
| public let date: String | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use stronger types here -- |
||
| public let hhmmss: String | ||
| public let driveTimeMinutes: Int | ||
| public let idleTimeMinutes: Int | ||
| public let distance: Double | ||
| public let avgSpeed: Double | ||
| public let maxSpeed: Double | ||
|
|
||
| public init(date: String, hhmmss: String, driveTimeMinutes: Int, idleTimeMinutes: Int, distance: Double, avgSpeed: Double, maxSpeed: Double) { | ||
| self.date = date | ||
| self.hhmmss = hhmmss | ||
| self.driveTimeMinutes = driveTimeMinutes | ||
| self.idleTimeMinutes = idleTimeMinutes | ||
| self.distance = distance | ||
| self.avgSpeed = avgSpeed | ||
| self.maxSpeed = maxSpeed | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can clear up all the naming here. Instead of having EVTripDetails and EVTripInfo, which is super unclear, we could have EVTripsSummary and EVTripInfo.
This
supportsEVTripDetails()would then return a list of EVTripType enums. US would return [EVTripSummary], EU would return [EVTripSummary, EVTripInfo]