|
5 | 5 | parallel flattened API - see ``commands.py`` docstrings. |
6 | 6 | """ |
7 | 7 |
|
8 | | -from tesla_protocol.command.car_server_pb2 import Action, SetRateTariffRequest |
9 | | -from tesla_protocol.command.universal_message_pb2 import Domain |
| 8 | +from tesla_protocol.command.car_server_pb2 import ( |
| 9 | + Action, |
| 10 | + GetManagedChargingSitesResponse, |
| 11 | + ManagedChargingSite, |
| 12 | + Response, |
| 13 | + SetRateTariffRequest, |
| 14 | +) |
| 15 | +from tesla_protocol.command.universal_message_pb2 import ( |
| 16 | + Destination, |
| 17 | + Domain, |
| 18 | + RoutableMessage, |
| 19 | +) |
10 | 20 |
|
11 | 21 | from ble_mocked_transport import ( |
12 | 22 | MockedBleTransportTestCase, |
@@ -117,3 +127,35 @@ async def test_sends_discharge_limit(self) -> None: |
117 | 127 |
|
118 | 128 | vehicle_action = _decode_vehicle_action(vehicle, send.await_args.args[0]) |
119 | 129 | self.assertEqual(vehicle_action.setDischargeLimitAction.discharge_limit, 50) |
| 130 | + |
| 131 | + |
| 132 | +class GetManagedChargingSitesDecodeTests(MockedBleTransportTestCase): |
| 133 | + def _reply(self, sites: list[ManagedChargingSite]) -> RoutableMessage: |
| 134 | + body = Response( |
| 135 | + getManagedChargingSitesResponse=GetManagedChargingSitesResponse(sites=sites) |
| 136 | + ) |
| 137 | + return RoutableMessage( |
| 138 | + from_destination=Destination(domain=Domain.DOMAIN_INFOTAINMENT), |
| 139 | + protobuf_message_as_bytes=body.SerializeToString(), |
| 140 | + ) |
| 141 | + |
| 142 | + async def test_returns_decoded_sites(self) -> None: |
| 143 | + vehicle, send = self.make_vehicle() |
| 144 | + send.return_value = self._reply([ManagedChargingSite(public_key="k1")]) |
| 145 | + |
| 146 | + result = await vehicle.get_managed_charging_sites() |
| 147 | + |
| 148 | + resp = result["response"] |
| 149 | + self.assertTrue(resp["result"]) |
| 150 | + sites = resp["getManagedChargingSitesResponse"].sites |
| 151 | + self.assertEqual([s.public_key for s in sites], ["k1"]) |
| 152 | + |
| 153 | + async def test_empty_list_is_distinguishable_from_undecoded(self) -> None: |
| 154 | + vehicle, send = self.make_vehicle() |
| 155 | + send.return_value = self._reply([]) |
| 156 | + |
| 157 | + result = await vehicle.get_managed_charging_sites() |
| 158 | + |
| 159 | + resp = result["response"] |
| 160 | + self.assertIn("getManagedChargingSitesResponse", resp) |
| 161 | + self.assertEqual(len(resp["getManagedChargingSitesResponse"].sites), 0) |
0 commit comments