Skip to content

Commit a4afc4c

Browse files
authored
Drop get_charging_settings from RenaultVehicle (#1556)
1 parent aba0df4 commit a4afc4c

File tree

4 files changed

+16
-134
lines changed

4 files changed

+16
-134
lines changed

src/renault_api/cli/charge/schedule.py

+16-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import re
44
from typing import Any
5+
from typing import cast
56

67
import aiohttp
78
import click
@@ -12,6 +13,8 @@
1213
from renault_api.kamereon.helpers import DAYS_OF_WEEK
1314
from renault_api.kamereon.models import ChargeDaySchedule
1415
from renault_api.kamereon.models import ChargeSchedule
16+
from renault_api.kamereon.models import KamereonVehicleChargingSettingsData
17+
from renault_api.kamereon.schemas import KamereonVehicleChargingSettingsDataSchema
1518
from renault_api.renault_vehicle import RenaultVehicle
1619

1720
_DAY_SCHEDULE_REGEX = re.compile(
@@ -44,13 +47,16 @@ async def show(
4447
vehicle = await renault_vehicle.get_vehicle(
4548
websession=websession, ctx_data=ctx_data
4649
)
47-
response = await vehicle.get_charge_schedule()
50+
full_endpoint = await vehicle.get_full_endpoint("charge-schedule")
51+
response = await vehicle.http_get(full_endpoint)
52+
if "data" in response.raw_data and "attributes" in response.raw_data["data"]:
53+
_show_basic(response.raw_data["data"]["attributes"])
54+
else:
55+
_show_alternate(response.raw_data)
4856

49-
# Display mode
50-
if "chargeModeRq" in response:
51-
_show_alternate(response)
52-
return
5357

58+
def _show_basic(response: dict[str, Any]) -> None:
59+
"""Display charge schedules (basic)."""
5460
calendar = response["calendar"]
5561
schedule_table: list[list[str]] = []
5662
for day in DAYS_OF_WEEK:
@@ -111,7 +117,11 @@ async def _get_schedule(
111117
vehicle = await renault_vehicle.get_vehicle(
112118
websession=websession, ctx_data=ctx_data
113119
)
114-
response = await vehicle.get_charging_settings()
120+
response_data = await vehicle._get_vehicle_data("charging-settings")
121+
response = cast(
122+
KamereonVehicleChargingSettingsData,
123+
response_data.get_attributes(KamereonVehicleChargingSettingsDataSchema),
124+
)
115125

116126
if not response.schedules:
117127
raise ValueError("No schedules found.")

src/renault_api/renault_vehicle.py

-16
Original file line numberDiff line numberDiff line change
@@ -231,22 +231,6 @@ async def get_res_state(self) -> models.KamereonVehicleResStateData:
231231
response.get_attributes(schemas.KamereonVehicleResStateDataSchema),
232232
)
233233

234-
async def get_charging_settings(self) -> models.KamereonVehicleChargingSettingsData:
235-
"""Get vehicle charging settings."""
236-
response = await self._get_vehicle_data("charging-settings")
237-
return cast(
238-
models.KamereonVehicleChargingSettingsData,
239-
response.get_attributes(schemas.KamereonVehicleChargingSettingsDataSchema),
240-
)
241-
242-
async def get_charge_schedule(self) -> dict[str, Any]:
243-
"""Get vehicle charging schedule."""
244-
full_endpoint = await self.get_full_endpoint("charge-schedule")
245-
response = await self.http_get(full_endpoint)
246-
if "data" in response.raw_data and "attributes" in response.raw_data["data"]:
247-
return response.raw_data["data"]["attributes"] # type:ignore[no-any-return]
248-
return response.raw_data
249-
250234
async def get_notification_settings(
251235
self,
252236
) -> models.KamereonVehicleNotificationSettingsData:

tests/__snapshots__/test_renault_vehicle.ambr

-82
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,4 @@
11
# serializer version: 1
2-
# name: test_get_charge_schedule
3-
dict({
4-
'calendar': dict({
5-
'friday': list([
6-
dict({
7-
'activationState': False,
8-
'duration': 480,
9-
'startTime': '2300',
10-
}),
11-
]),
12-
'monday': list([
13-
dict({
14-
'activationState': False,
15-
'duration': 480,
16-
'startTime': '2300',
17-
}),
18-
]),
19-
'saturday': list([
20-
dict({
21-
'activationState': False,
22-
'duration': 480,
23-
'startTime': '2300',
24-
}),
25-
]),
26-
'sunday': list([
27-
dict({
28-
'activationState': False,
29-
'duration': 480,
30-
'startTime': '2300',
31-
}),
32-
]),
33-
'thursday': list([
34-
dict({
35-
'activationState': False,
36-
'duration': 480,
37-
'startTime': '2300',
38-
}),
39-
]),
40-
'tuesday': list([
41-
dict({
42-
'activationState': False,
43-
'duration': 480,
44-
'startTime': '2300',
45-
}),
46-
]),
47-
'wednesday': list([
48-
dict({
49-
'activationState': False,
50-
'duration': 480,
51-
'startTime': '2300',
52-
}),
53-
]),
54-
}),
55-
})
56-
# ---
57-
# name: test_get_charge_schedule_alternate
58-
dict({
59-
'chargeDuration': 9000,
60-
'chargeModeRq': 'SCHEDULED',
61-
'chargeTimeStart': '00:00',
62-
'delegatedActivated': False,
63-
'lastSettingsUpdateTimestamp': '2025-04-24T12:17:12.247Z',
64-
'preconditioningHeatedLeftSeat': False,
65-
'preconditioningHeatedRightSeat': False,
66-
'preconditioningHeatedStrgWheel': False,
67-
'preconditioningTemperature': 20.0,
68-
'programs': list([
69-
dict({
70-
'programActivationFriday': True,
71-
'programActivationMonday': True,
72-
'programActivationSaturday': True,
73-
'programActivationStatus': True,
74-
'programActivationSunday': True,
75-
'programActivationThursday': True,
76-
'programActivationTuesday': True,
77-
'programActivationWednesday': True,
78-
'programDepartureTime': '02:00',
79-
'programType': 'CHARGE_AND_PRECONDITIONING',
80-
}),
81-
]),
82-
})
83-
# ---
842
# name: test_get_endpoints[tests/fixtures/kamereon/vehicles/captur_ii.1.json]
853
dict({
864
'hvac-status': None,

tests/test_renault_vehicle.py

-30
Original file line numberDiff line numberDiff line change
@@ -188,36 +188,6 @@ async def test_get_lock_status(
188188
assert await vehicle.get_lock_status()
189189

190190

191-
@pytest.mark.asyncio
192-
async def test_get_charging_settings(
193-
vehicle: RenaultVehicle, mocked_responses: aioresponses
194-
) -> None:
195-
"""Test get_charging_settings."""
196-
fixtures.inject_get_vehicle_details(mocked_responses, "zoe_50.1.json")
197-
fixtures.inject_get_charging_settings(mocked_responses, "multi")
198-
assert await vehicle.get_charging_settings()
199-
200-
201-
@pytest.mark.asyncio
202-
async def test_get_charge_schedule(
203-
vehicle: RenaultVehicle, mocked_responses: aioresponses, snapshot: SnapshotAssertion
204-
) -> None:
205-
"""Test get_charging_settings."""
206-
fixtures.inject_get_vehicle_details(mocked_responses, "zoe_50.1.json")
207-
fixtures.inject_get_charge_schedule(mocked_responses, "single")
208-
assert await vehicle.get_charge_schedule() == snapshot
209-
210-
211-
@pytest.mark.asyncio
212-
async def test_get_charge_schedule_alternate(
213-
vehicle: RenaultVehicle, mocked_responses: aioresponses, snapshot: SnapshotAssertion
214-
) -> None:
215-
"""Test get_charging_settings."""
216-
fixtures.inject_get_vehicle_details(mocked_responses, "renault_5.1.json")
217-
fixtures.inject_get_ev_settings(mocked_responses, "single")
218-
assert await vehicle.get_charge_schedule() == snapshot
219-
220-
221191
@pytest.mark.asyncio
222192
async def test_get_notification_settings(
223193
vehicle: RenaultVehicle, mocked_responses: aioresponses

0 commit comments

Comments
 (0)