-
Notifications
You must be signed in to change notification settings - Fork 15
feat(vehicle): add charging/utility signed commands #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| """Charging/utility commands over the mocked BLE transport. | ||
|
|
||
| ``set_rate_tariff``/``add_managed_charging_site`` accept ``tesla_protocol`` | ||
| message types directly for their deeply-nested arguments rather than a | ||
| parallel flattened API - see ``commands.py`` docstrings. | ||
| """ | ||
|
|
||
| from tesla_protocol.command.car_server_pb2 import Action, SetRateTariffRequest | ||
| from tesla_protocol.command.universal_message_pb2 import Domain | ||
|
|
||
| from ble_mocked_transport import ( | ||
| MockedBleTransportTestCase, | ||
| decrypt_sent_command, | ||
| infotainment_action_ok_reply, | ||
| ) | ||
|
|
||
|
|
||
| def _decode_vehicle_action(vehicle, sent_msg): | ||
| plaintext = decrypt_sent_command(vehicle, sent_msg) | ||
| action = Action.FromString(plaintext) | ||
| assert sent_msg.to_destination.domain == Domain.DOMAIN_INFOTAINMENT | ||
| return action.vehicleAction | ||
|
|
||
|
|
||
| class SetRateTariffTests(MockedBleTransportTestCase): | ||
| async def test_sends_seasons_only(self) -> None: | ||
| vehicle, send = self.make_vehicle() | ||
| send.return_value = infotainment_action_ok_reply() | ||
|
|
||
| seasons = SetRateTariffRequest.Seasons( | ||
| Summer=SetRateTariffRequest.Season(from_month=6, to_month=8) | ||
| ) | ||
| await vehicle.set_rate_tariff(seasons) | ||
|
|
||
| vehicle_action = _decode_vehicle_action(vehicle, send.await_args.args[0]) | ||
| action = vehicle_action.setRateTariffRequest | ||
| self.assertEqual(action.seasons.Summer.from_month, 6) | ||
| self.assertEqual(action.seasons.Summer.to_month, 8) | ||
| self.assertFalse(action.HasField("tariff")) | ||
|
|
||
| async def test_sends_tariff_when_given(self) -> None: | ||
| vehicle, send = self.make_vehicle() | ||
| send.return_value = infotainment_action_ok_reply() | ||
|
|
||
| seasons = SetRateTariffRequest.Seasons() | ||
| tariff = SetRateTariffRequest.Tariff(seasons=seasons) | ||
| await vehicle.set_rate_tariff(seasons, tariff) | ||
|
|
||
| vehicle_action = _decode_vehicle_action(vehicle, send.await_args.args[0]) | ||
| action = vehicle_action.setRateTariffRequest | ||
| self.assertTrue(action.HasField("tariff")) | ||
|
|
||
|
|
||
| class GetRateTariffTests(MockedBleTransportTestCase): | ||
| async def test_sends_get_rate_tariff_request(self) -> None: | ||
| vehicle, send = self.make_vehicle() | ||
| send.return_value = infotainment_action_ok_reply() | ||
|
|
||
| await vehicle.get_rate_tariff() | ||
|
|
||
| vehicle_action = _decode_vehicle_action(vehicle, send.await_args.args[0]) | ||
| self.assertTrue(vehicle_action.HasField("getRateTariffRequest")) | ||
|
|
||
|
|
||
| class AddManagedChargingSiteTests(MockedBleTransportTestCase): | ||
| async def test_sends_public_key_and_coordinates(self) -> None: | ||
| vehicle, send = self.make_vehicle() | ||
| send.return_value = infotainment_action_ok_reply() | ||
|
|
||
| await vehicle.add_managed_charging_site("pubkey-bytes", 37.3230, -122.0322) | ||
|
|
||
| vehicle_action = _decode_vehicle_action(vehicle, send.await_args.args[0]) | ||
| site = vehicle_action.addManagedChargingSiteRequest.site | ||
| self.assertEqual(site.public_key, "pubkey-bytes") | ||
| self.assertTrue(site.manager_type.HasField("site_controller")) | ||
| # LatLong lat/lon are 32-bit floats, so compare at reduced precision. | ||
| self.assertAlmostEqual(site.lat_lon.latitude, 37.3230, places=4) | ||
| self.assertAlmostEqual(site.lat_lon.longitude, -122.0322, places=4) | ||
|
|
||
|
|
||
| class RemoveManagedChargingSiteTests(MockedBleTransportTestCase): | ||
| async def test_sends_public_key(self) -> None: | ||
| vehicle, send = self.make_vehicle() | ||
| send.return_value = infotainment_action_ok_reply() | ||
|
|
||
| await vehicle.remove_managed_charging_site("pubkey-bytes") | ||
|
|
||
| vehicle_action = _decode_vehicle_action(vehicle, send.await_args.args[0]) | ||
| self.assertEqual( | ||
| vehicle_action.removeManagedChargingSiteRequest.public_key, | ||
| "pubkey-bytes", | ||
| ) | ||
|
|
||
|
|
||
| class GetManagedChargingSitesTests(MockedBleTransportTestCase): | ||
| async def test_sends_get_managed_charging_sites_request(self) -> None: | ||
| vehicle, send = self.make_vehicle() | ||
| send.return_value = infotainment_action_ok_reply() | ||
|
|
||
| await vehicle.get_managed_charging_sites() | ||
|
|
||
| vehicle_action = _decode_vehicle_action(vehicle, send.await_args.args[0]) | ||
| self.assertTrue(vehicle_action.HasField("getManagedChargingSitesRequest")) | ||
|
|
||
|
|
||
| class SetDischargeLimitTests(MockedBleTransportTestCase): | ||
| async def test_sends_discharge_limit(self) -> None: | ||
| vehicle, send = self.make_vehicle() | ||
| send.return_value = infotainment_action_ok_reply() | ||
|
|
||
| await vehicle.set_discharge_limit(50) | ||
|
|
||
| vehicle_action = _decode_vehicle_action(vehicle, send.await_args.args[0]) | ||
| self.assertEqual(vehicle_action.setDischargeLimitAction.discharge_limit, 50) |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a vehicle replies to this read with the normal infotainment
Response.getRateTariffResponse(and similarlygetManagedChargingSitesResponsebelow),Commands._commandonly unwrapsping,vehicleData, oractionStatus; otherwise it falls through to{"result": True}. As a result these newly added getter APIs can successfully send the request but discard the tariff/site payload, so callers cannot actually read the data the methods advertise; extend the response decoding for these oneof fields before exposing the getters.Useful? React with 👍 / 👎.