Repository navigation
Check params in encode_vehicle_command - #254
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #245.
encode_vehicle_commandrelied on callers runningRivian.validate_vehicle_commandfirst. Called without it:CHARGING_LIMITS {"SOC_limit": 150}RivianBadRequestErrorCABIN_PRECONDITIONING_SET_TEMP {"HVAC_set_temp": 45}RivianBadRequestErrorCABIN_HVAC_DEFROST_DEFOG {"level": "0"}RivianBadRequestError{"SOC_limit": "80"},{"HVAC_set_temp": "abc"}TypeError/ValueErrorRivianBadRequestErrorCHARGING_LIMITSwith no paramsChanges
check_charge_limit,check_hvac_levelandcheck_temperatureinparallax/vehicle_command.pyare used by bothencode_vehicle_commandandRivian.validate_vehicle_command, so the two can't drift apart. The broadKeyErrorcatch is gone.{"level": True}and the legacy command sent it as level 1. That's the only change to what the validator accepts.SEAT_ROW_1_LEFT level 1 has no Parallax equivalent.send_vehicle_commandnow saysHVAC_set_tempis a number, which is what the validator has always required.Testing
test_validation_agreeschecks 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.main.🤖 Generated with Claude Code