Skip to content

Commit

Permalink
Add support for 2-character manufacturer codes in the WMI
Browse files Browse the repository at this point in the history
Some manufacturers use the first 2 characters of the WMI as the
manufacturer ID, with the 3rd denoting the specific class of vehicle
specific to that manufacturer.

Fixes #7.
  • Loading branch information
pmundt committed May 29, 2021
1 parent 01dd2a6 commit 3763cf9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.1

- Support VINs with 2-character manufacturer IDs in their WMI (reported by @huangkaichang, issue #7)

## 0.2.0-nullsafety

- Migrate for null safety
Expand Down
10 changes: 9 additions & 1 deletion lib/src/vin_decoder_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,18 @@ class VIN {

/// Get the full name of the vehicle manufacturer as defined by the [wmi].
String? getManufacturer() {
// Check for the standard case - a 3 character WMI
if (manufacturers.containsKey(this.wmi)) {
return manufacturers[this.wmi];
} else {
return "Unknown (WMI: ${this.wmi.toUpperCase()})";
// Some manufacturers only use the first 2 characters for manufacturer
// identification, and the third for the class of vehicle.
var id = this.wmi.substring(0, 2);
if (manufacturers.containsKey(id)) {
return manufacturers[id];
} else {
return "Unknown (WMI: ${this.wmi.toUpperCase()})";
}
}
}

Expand Down
22 changes: 22 additions & 0 deletions test/vin_decoder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,26 @@ void main() {
expect(vin.getRegion(), 'AS');
});
});

group('2-character WMI Manufacturer Test', () {
late VIN vin;

setUp(() {
// Here the first 2 characters refer to the manufacturer, with the 3rd
// representing the class of vehicle specific to that manufacturer.
vin = VIN(number: '5TENL42N94Z436445');
});

test('Validity Test', () {
expect(vin.valid(), isTrue);
});

test('Region Test', () {
expect(vin.getRegion(), 'NA');
});

test('Manufacturer Test', () {
expect(vin.getManufacturer(), 'Toyota - trucks');
});
});
}

0 comments on commit 3763cf9

Please sign in to comment.