Skip to content

fix(RequestService): route alert commands to v1 API for ICE vehicles v3 for EV/Hybrid#498

Open
BigThunderSR wants to merge 2 commits intomasterfrom
fix/alert-commands-api-routing
Open

fix(RequestService): route alert commands to v1 API for ICE vehicles v3 for EV/Hybrid#498
BigThunderSR wants to merge 2 commits intomasterfrom
fix/alert-commands-api-routing

Conversation

@BigThunderSR
Copy link
Owner

@BigThunderSR BigThunderSR commented Oct 9, 2025

Fix alert commands failing with 400 Bad Request on ICE vehicles

Problem

Alert and flash light commands (alert(), flashLights(), cancelAlert(), stopLights()) fail with HTTP 400 errors on Internal Combustion Engine (ICE) vehicles. The v3 API endpoint (/veh/cmd/v3/alert/{VIN}) does not support these commands for ICE vehicles.

Solution

Implement automatic API version routing based on vehicle engine type:

  • ICE vehicles: v1 API (/api/v1/account/vehicles/{VIN}/commands/alert)
  • EV/Hybrid vehicles: v3 API (/veh/cmd/v3/alert/{VIN})

Implementation

Engine Type Detection

  1. Primary: Parse ENGINE_TYPE from diagnostics API diagnosticElements array
  2. Fallback: Check for fuel level diagnostics (ICE) or battery diagnostics (EV/Hybrid)
  3. Default: Assume ICE if detection fails

Caching

  • Memory cache: Persists for request service instance lifetime
  • Disk cache: Saves to vehicle_type_{VIN}.json to minimize diagnostics API calls across sessions
  • Cache files excluded via .gitignore and .npmignore

Methods

  • isICEVehicle(): Determines engine type with caching
  • loadVehicleTypeFromDisk(): Reads cached type from disk
  • saveVehicleTypeToDisk(): Persists type to disk
  • getVehicleTypeCachePath(): Returns cache file path

Testing

Unit Tests (12 new tests)

  • ENGINE_TYPE detection for ICE and EV vehicles
  • Fuel level and battery fallback detection
  • Memory and disk caching behavior
  • API routing verification for both vehicle types

Functional Tests

  • Updated to handle both v1 (commandResponse) and v3 (status/requestId) response structures

Coverage

  • Statements: 88.74%
  • Branches: 80.23%
  • Functions: 94.39%
  • Lines: 88.52%

Files Changed

  • src/RequestService.ts (+178 lines): Detection and routing logic
  • test/unit/RequestService.test.ts (+195 lines): Comprehensive test coverage
  • test/functional/OnStarJs.test.ts (+17 lines): Handle both API versions
  • .gitignore, .npmignore (+3 lines each): Exclude cache files

… v3 for EV/Hybrid

- Add intelligent API version routing for alert/flash commands based on engine type
- Detect vehicle engine type (ICE vs EV/Hybrid) from diagnostics data
- ICE vehicles use v1 API endpoint (/api/v1/account/vehicles/{VIN}/commands/alert)
- EV/Hybrid vehicles use v3 API endpoint (/veh/cmd/v3/alert/{VIN})
- Implement disk-based caching of engine type to minimize API calls
- Cache persists across sessions in vehicle_type_{VIN}.json
- Add vehicle_type_*.json to .gitignore and .npmignore

Fixes issue where alert/flashLights commands were failing with 400 Bad Request
for ICE vehicles due to v3 API incompatibility.

Related commands affected:
- alert()
- flashLights()
- cancelAlert()
- stopLights()
@coveralls
Copy link

coveralls commented Oct 9, 2025

Pull Request Test Coverage Report for Build 18390876940

Details

  • 60 of 75 (80.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-2.9%) to 91.959%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/RequestService.ts 60 75 80.0%
Totals Coverage Status
Change from base Build 18387494128: -2.9%
Covered Lines: 430
Relevant Lines: 453

💛 - Coveralls

…uting

- Add 12 new unit tests covering:
  - ENGINE_TYPE detection from diagnostics (ICE and EV)
  - Fuel level fallback detection (ICE)
  - Battery diagnostics fallback detection (EV)
  - Memory caching behavior
  - Disk caching behavior
  - API endpoint routing for both vehicle types
  - v1 API usage for ICE vehicles
  - v3 API usage for EV vehicles

- Update functional test to handle both v1 and v3 API response structures
- Add beforeEach hook to clear cache between tests
- Mock disk I/O operations to avoid file system side effects

Coverage improved:
- Statements: 88.74%
- Branches: 80.23%
- Functions: 94.39%
- Lines: 88.52%
@BigThunderSR BigThunderSR added the duplicate This issue or pull request already exists label Oct 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants