Skip to content

Check params in encode_vehicle_command - #254

Merged
natekspencer merged 3 commits into
mainfrom
vehicle-command-params
Nov 16, 2026
Merged

natekspencer merged 3 commits into
mainfrom
vehicle-command-params

Conversation

@natekspencer

@natekspencer natekspencer commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #245.

encode_vehicle_command relied on callers running Rivian.validate_vehicle_command first. Called without it:

Params Before After
CHARGING_LIMITS {"SOC_limit": 150} sends a limit of 150 RivianBadRequestError
CABIN_PRECONDITIONING_SET_TEMP {"HVAC_set_temp": 45} sends 45 °C RivianBadRequestError
CABIN_HVAC_DEFROST_DEFOG {"level": "0"} turns defrost on RivianBadRequestError
{"SOC_limit": "80"}, {"HVAC_set_temp": "abc"} raw TypeError / ValueError RivianBadRequestError
CHARGING_LIMITS with no params "has no Parallax equivalent" "must include parameter `SOC_limit` …"

Changes

  • One set of rules. check_charge_limit, check_hvac_level and check_temperature in parallax/vehicle_command.py are used by both encode_vehicle_command and Rivian.validate_vehicle_command, so the two can't drift apart. The broad KeyError catch is gone.
  • Bool params are rejected on both paths. Before, the validator accepted {"level": True} and the legacy command sent it as level 1. That's the only change to what the validator accepts.
  • Clearer errors. An invalid param gets the validator's existing message. A valid level the Parallax command doesn't have says so, e.g. SEAT_ROW_1_LEFT level 1 has no Parallax equivalent.
  • Docstring. send_vehicle_command now says HVAC_set_temp is a number, which is what the validator has always required.

Testing

  • New tests cover the range edges on both paths (50/100, 16/29/0/63.5, levels 0–4 accepted; 49/101, 15.5/29.5, strings and bools rejected).
  • test_validation_agrees checks that the validator and encoder accept the same params for every Parallax command. The only exceptions allowed are seat level 1 and steering wheel level 4.
  • Valid params encode byte-for-byte as before. I compared 1,950 combinations against main.

🤖 Generated with Claude Code

natekspencer and others added 3 commits November 16, 2026 01:24
encode_vehicle_command relied on callers having run
Rivian.validate_vehicle_command first. Without it, some invalid params
encoded into real commands (a charge limit of 150, 45 °C, defrost
level "0" turning defrost on), others raised a raw TypeError or
ValueError, and a missing param was reported as "has no Parallax
equivalent".

Each command now checks its params the way validate_vehicle_command
does, and the broad KeyError catch is gone. Valid params encode
exactly as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The param rules were written out twice, in validate_vehicle_command and
in encode_vehicle_command, and already differed on bool levels. They
now live once in parallax/vehicle_command.py (check_charge_limit,
check_hvac_level, check_temperature), and validate_vehicle_command
calls them. Bool params are rejected on both paths.

Errors now tell an invalid param ("must include parameter ...") apart
from a valid level the Parallax command doesn't have ("SEAT_ROW_1_LEFT
level 1 has no Parallax equivalent"). Tests cover the range edges and
check that the validator and encoder accept the same params.

The send_vehicle_command docstring now says HVAC_set_temp is a number,
which is what the validator has always required.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
send_vehicle_command converted HVAC_set_temp to a string in the
caller's dict, so sending the same params again failed validation,
which only accepts a number. It now sends a copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@natekspencer
natekspencer merged commit 766ddc3 into main Nov 16, 2026
6 checks passed
@natekspencer
natekspencer deleted the vehicle-command-params branch November 16, 2026 01:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant