@bytebrand/export-cars 1.26.26 → 1.26.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytebrand/export-cars",
3
- "version": "1.26.26",
3
+ "version": "1.26.27",
4
4
  "description": "",
5
5
  "author": "bytebrand",
6
6
  "license": "UNLICENSED",
@@ -72,9 +72,15 @@ const isConfirmedPlugIn = (car: DataSchemes.Car): boolean => isPlugIn(car) && !!
72
72
  // (CBD mirrors kWh into consumptionCombined for them).
73
73
  export function googleFuelConsumption(car: DataSchemes.Car): string | undefined {
74
74
  if (isBev(car)) return undefined;
75
- const value = isConfirmedPlugIn(car)
76
- ? positive(get(car, 'consumption.wltpWeightedCombined')) ?? positive(get(car, 'consumption.consumptionCombined'))
77
- : positive(get(car, 'consumption.consumptionCombined'));
75
+ let value: number | undefined;
76
+ if (isConfirmedPlugIn(car)) {
77
+ value = positive(get(car, 'consumption.wltpWeightedCombined')) ?? positive(get(car, 'consumption.consumptionCombined'));
78
+ } else if (isPlugIn(car)) {
79
+ value = positive(get(car, 'consumption.consumptionCombined')); // unconfirmed plug-in: as before
80
+ } else {
81
+ // ICE / HEV: the WLTP combined value the VDP and EnVKV use (EnVKV stage D3), the legacy field as fallback
82
+ value = positive(get(car, 'consumption.wltpCombined')) ?? positive(get(car, 'consumption.consumptionCombined'));
83
+ }
78
84
  return value ? `${value}l/100km` : undefined;
79
85
  }
80
86
 
@@ -105,8 +111,10 @@ export function googleEnergyConsumption(car: DataSchemes.Car): string | undefine
105
111
  // the stored value. A missing or 0 value is omitted.
106
112
  export function googleCo2(car: DataSchemes.Car): string | undefined {
107
113
  if (isBev(car)) return '0g/km';
108
- const value = isConfirmedPlugIn(car)
109
- ? positive(get(car, 'environmentEmissions.wltpCo2')) ?? positive(get(car, 'environmentEmissions.co2'))
110
- : positive(get(car, 'environmentEmissions.co2'));
114
+ // a confirmed plug-in and ICE / HEV send the WLTP value (weighted for the plug-in); an unconfirmed
115
+ // plug-in keeps the stored legacy value, as before
116
+ const value = isPlugIn(car) && !isConfirmedPlugIn(car)
117
+ ? positive(get(car, 'environmentEmissions.co2'))
118
+ : positive(get(car, 'environmentEmissions.wltpCo2')) ?? positive(get(car, 'environmentEmissions.co2'));
111
119
  return value ? `${value}g/km` : undefined;
112
120
  }
@@ -87,15 +87,20 @@ const cases: Array<[string, () => void]> = [
87
87
  assert.equal(googleEnergyConsumption(phev), undefined);
88
88
  assert.equal(googleCo2(phev), '32g/km');
89
89
  }],
90
- ['non-plug-in hybrids and combustion cars keep the stored values and send no electricity', () => {
90
+ ['non-plug-in hybrids and combustion cars send the WLTP values (legacy as fallback) and no electricity', () => {
91
91
  const hev = car('selector_fuel_hybridElectricalPetrol', {
92
92
  consumption: { consumptionCombined: 5.1, wltpCombined: 5.3, wltpWeightedCombined: 2.3, wltpWeightedPowerCombined: 21.5 },
93
93
  environmentEmissions: { co2: 116, wltpCo2: 119 },
94
94
  });
95
- assert.equal(googleFuelConsumption(hev), '5.1l/100km');
95
+ assert.equal(googleFuelConsumption(hev), '5.3l/100km');
96
96
  assert.equal(googleFuelConsumptionDischarged(hev), undefined);
97
97
  assert.equal(googleEnergyConsumption(hev), undefined);
98
- assert.equal(googleCo2(hev), '116g/km');
98
+ assert.equal(googleCo2(hev), '119g/km');
99
+ // D3: Mercedes GLC 200 sent 146.7 g (legacy) while CBD / VDP / EnVKV hold the dealer's WLTP 138 g
100
+ const glc = car('selector_fuel_diesel', { consumption: { consumptionCombined: 5.6, wltpCombined: 5.2 }, environmentEmissions: { co2: 146.7, wltpCo2: 138 } });
101
+ assert.equal(googleCo2(glc), '138g/km');
102
+ assert.equal(googleFuelConsumption(glc), '5.2l/100km');
103
+ assert.equal(googleCo2(car('selector_fuel_diesel', { environmentEmissions: { co2: 150 } })), '150g/km');
99
104
  }],
100
105
  ['a plug-in flag without an electric range keeps the stored values (ADV-124 flags every hybrid)', () => {
101
106
  const flagged = car('selector_fuel_hybridElectricalPetrol', {