Skip to content

Commit

Permalink
Added VINComponents. Updated VIN initializer and added confomrance to…
Browse files Browse the repository at this point in the history
… CustomStringConverible. Added additional VIN unit test cases. Updated docs.
  • Loading branch information
Jaren Hamblin committed Apr 12, 2018
1 parent bb538a8 commit 06f5244
Show file tree
Hide file tree
Showing 116 changed files with 1,914 additions and 458 deletions.
15 changes: 5 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ TeslaKit is a framework written in Swift that makes it easy for you to interface
- [x] Send commands to your vehicle
- [x] Utilizes `ObjectMapper` for `JSON` mapping
- [x] Uses `Structures` to maintain thread safe operations
- [x] VIN parsing
- [ ] Summon and Homelink - Coming soon

# Installation
Expand Down Expand Up @@ -148,16 +149,6 @@ Enabling debug mode will print all request information to the console (default:
let teslaAPI = TeslaAPI(debugMode: true)
```

```json
{
"access_token": "abc123",
"token_type": "bearer",
"expires_in": 7776000,
"created_at": 1457385291,
"refresh_token": "cba321"
}
```

## Request Timeout

Specify request timeout interval (default: ```30```)
Expand All @@ -166,7 +157,11 @@ Specify request timeout interval (default: ```30```)
let teslaAPI = TeslaAPI(requestTimeout: 15)
```

# VIN Parsing

## VIN

## VINCompnonent


# Author
Expand Down
38 changes: 25 additions & 13 deletions Source/Structures/VIN.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import ObjectMapper

///
public struct VIN {
public struct VIN: CustomStringConvertible {

/// The minimum length to allow VIN parsing
public static let minimumLength: Int = 15
Expand All @@ -19,10 +19,10 @@ public struct VIN {
public var vinString: String = ""

///
public var manufacturer: VINComponent.Manufacturer = VINComponent.Manufacturer.tesla
public var manufacturer: VINComponent.Manufacturer = .unknown

///
public var make: VINComponent.Make = VINComponent.Make.modelS
public var make: VINComponent.Make = .unknown

///
public var bodyType: String = ""
Expand All @@ -31,16 +31,22 @@ public struct VIN {
public var restraintSystem: String = ""

///
public var driveUnit: VINComponent.DriveUnit = VINComponent.DriveUnit.singleMotor
public var batteryType: VINComponent.BatteryType = .unknown

///
public var driveUnit: VINComponent.DriveUnit = .unknown

///
public var checkCharacter: String = ""

///
public var modelYear: VINComponent.ModelYear = VINComponent.ModelYear.unknown
public var modelYear: VINComponent.ModelYear = .unknown

///
public var manufactureLocation: VINComponent.ManufactureLocation = .unknown

///
public var manufactureLocation: String = ""
public var serialCharacter: String = ""

///
public var serialNo: String = ""
Expand All @@ -53,16 +59,22 @@ public struct VIN {
guard vinString.count > VIN.minimumLength else { return nil }
let vin: String = vinString.uppercased()
self.vinString = vin
self.manufacturer = VINComponent.Manufacturer(rawValue: String(vin[0..<3])) ?? VINComponent.Manufacturer.tesla
self.make = VINComponent.Make(rawValue: String(vin[3..<4])) ?? VINComponent.Make.unknown
self.manufacturer = VINComponent.Manufacturer(rawValue: String(vin[0..<3])) ?? .unknown
self.make = VINComponent.Make(rawValue: String(vin[3..<4])) ?? .unknown
self.bodyType = String(vin[4..<5])
self.restraintSystem = String(vin[5..<6])
self.bodyType = String(vin[6..<7])
self.driveUnit = VINComponent.DriveUnit(rawValue: String(vin[7..<8])) ?? VINComponent.DriveUnit.singleMotor
self.batteryType = VINComponent.BatteryType(rawValue: String(vin[6..<7])) ?? .unknown
self.driveUnit = VINComponent.DriveUnit(rawValue: String(vin[7..<8])) ?? .unknown
self.checkCharacter = String(vin[8..<9])
self.modelYear = VINComponent.ModelYear(rawValue: String(vin[9..<10])) ?? VINComponent.ModelYear.unknown
self.manufactureLocation = String(vin[10..<11])
self.serialNo = String(vin[11...vin.count-1])
self.modelYear = VINComponent.ModelYear(rawValue: String(vin[9..<10])) ?? .unknown
self.manufactureLocation = VINComponent.ManufactureLocation(rawValue: String(vin[10..<11])) ?? .unknown
self.serialCharacter = String(vin[11..<12])
self.serialNo = String(vin[12...vin.count-1])
}

///
public var description: String {
return self.vinString
}
}

Expand Down
74 changes: 66 additions & 8 deletions Source/Structures/VINComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,25 @@ import Foundation
public struct VINComponent {

///
public enum Manufacturer: String {
public enum Manufacturer: String, CustomStringConvertible, EnumCollection {

///
case unknown = ""

///
case tesla = "5YJ"

///
public var description: String {
switch self {
case .unknown: return "Unknown"
case .tesla: return "Tesla"
}
}
}

///
public enum Make: String {
public enum Make: String, CustomStringConvertible, EnumCollection {

///
case unknown = ""
Expand All @@ -36,8 +47,8 @@ public struct VINComponent {
///
case model3 = "3"

/// A readable display name
public var name: String {
///
public var description: String {
switch self {
case .unknown: return "Unknown"
case .roadster: return "Roadster"
Expand All @@ -49,7 +60,10 @@ public struct VINComponent {
}

///
public enum BatteryType: String {
public enum BatteryType: String, CustomStringConvertible, EnumCollection {

///
case unknown

///
case electric = "E"
Expand All @@ -62,10 +76,24 @@ public struct VINComponent {

///
case ultraCapacity = "V"

///
public var description: String {
switch self {
case .unknown: return "Unknown"
case .electric: return "Electric"
case .highCapacity: return "High Capacity"
case .standardCapacity: return "Standard Capacity"
case .ultraCapacity: return "Ultra Capacity"
}
}
}

///
public enum DriveUnit: String {
public enum DriveUnit: String, CustomStringConvertible, EnumCollection {

///
case unknown

///
case singleMotor = "1"
Expand All @@ -81,10 +109,40 @@ public struct VINComponent {

///
case performance = "P"

///
public var description: String {
switch self {
case .unknown: return "Unknown"
case .singleMotor: return "Single Motor"
case .dualMotor: return "Dual Motor"
case .performanceSingleMotor: return "Performance Single Motor"
case .performanceDualMotor: return "Performance Dual Motor"
case .performance: return "Performance"
}
}
}

///
public enum ManufactureLocation: String, CustomStringConvertible, EnumCollection {

///
case unknown = ""

///
case fremont = "F"

///
public var description: String {
switch self {
case .unknown: return "Unknown"
case .fremont: return "Fremont, CA, USA"
}
}
}

///
public enum ModelYear: String {
public enum ModelYear: String, EnumCollection {

///
case unknown = ""
Expand Down Expand Up @@ -150,7 +208,7 @@ public struct VINComponent {
case year2006 = "6"

///
public var name: String {
public var description: String {
return String(describing: self).replacingOccurrences(of: "year", with: "")
}
}
Expand Down
Loading

0 comments on commit 06f5244

Please sign in to comment.