10
10
import aiohttp
11
11
12
12
from .credential_store import CredentialStore
13
+ from .exceptions import EndpointNotAvailableError
13
14
from .exceptions import RenaultException
15
+ from .kamereon import ACCOUNT_ENDPOINT_ROOT
14
16
from .kamereon import models
15
17
from .kamereon import schemas
16
18
from .renault_session import RenaultSession
@@ -77,6 +79,25 @@ def vin(self) -> str:
77
79
"""Get vin."""
78
80
return self ._vin
79
81
82
+ async def _get_vehicle_data (
83
+ self , endpoint : str
84
+ ) -> models .KamereonVehicleDataResponse :
85
+ """GET to /v{endpoint_version}/cars/{vin}/{endpoint}."""
86
+ details = await self .get_details ()
87
+ full_endpoint = details .get_endpoint (endpoint )
88
+ if full_endpoint is None :
89
+ raise EndpointNotAvailableError (endpoint , details .get_model_code ())
90
+
91
+ full_endpoint = ACCOUNT_ENDPOINT_ROOT .replace (
92
+ "{account_id}" , self .account_id
93
+ ) + full_endpoint .replace ("{vin}" , self .vin )
94
+
95
+ schema = schemas .KamereonVehicleDataResponseSchema
96
+ return cast (
97
+ models .KamereonVehicleDataResponse ,
98
+ await self .session .http_request ("GET" , full_endpoint , schema = schema ),
99
+ )
100
+
80
101
async def get_details (self ) -> models .KamereonVehicleDetails :
81
102
"""Get vehicle details."""
82
103
if self ._vehicle_details :
@@ -124,119 +145,79 @@ async def get_contracts(self) -> list[models.KamereonVehicleContract]:
124
145
125
146
async def get_battery_status (self ) -> models .KamereonVehicleBatteryStatusData :
126
147
"""Get vehicle battery status."""
127
- response = await self .session .get_vehicle_data (
128
- account_id = self .account_id ,
129
- vin = self .vin ,
130
- endpoint = "battery-status" ,
131
- )
148
+ response = await self ._get_vehicle_data ("battery-status" )
132
149
return cast (
133
150
models .KamereonVehicleBatteryStatusData ,
134
151
response .get_attributes (schemas .KamereonVehicleBatteryStatusDataSchema ),
135
152
)
136
153
137
154
async def get_tyre_pressure (self ) -> models .KamereonVehicleTyrePressureData :
138
155
"""Get vehicle tyre pressure."""
139
- response = await self .session .get_vehicle_data (
140
- account_id = self .account_id ,
141
- vin = self .vin ,
142
- endpoint = "pressure" ,
143
- )
156
+ response = await self ._get_vehicle_data ("pressure" )
144
157
return cast (
145
158
models .KamereonVehicleTyrePressureData ,
146
159
response .get_attributes (schemas .KamereonVehicleTyrePressureDataSchema ),
147
160
)
148
161
149
162
async def get_location (self ) -> models .KamereonVehicleLocationData :
150
163
"""Get vehicle location."""
151
- response = await self .session .get_vehicle_data (
152
- account_id = self .account_id ,
153
- vin = self .vin ,
154
- endpoint = "location" ,
155
- )
164
+ response = await self ._get_vehicle_data ("location" )
156
165
return cast (
157
166
models .KamereonVehicleLocationData ,
158
167
response .get_attributes (schemas .KamereonVehicleLocationDataSchema ),
159
168
)
160
169
161
170
async def get_hvac_status (self ) -> models .KamereonVehicleHvacStatusData :
162
171
"""Get vehicle hvac status."""
163
- response = await self .session .get_vehicle_data (
164
- account_id = self .account_id ,
165
- vin = self .vin ,
166
- endpoint = "hvac-status" ,
167
- )
172
+ response = await self ._get_vehicle_data ("hvac-status" )
168
173
return cast (
169
174
models .KamereonVehicleHvacStatusData ,
170
175
response .get_attributes (schemas .KamereonVehicleHvacStatusDataSchema ),
171
176
)
172
177
173
178
async def get_hvac_settings (self ) -> models .KamereonVehicleHvacSettingsData :
174
179
"""Get vehicle hvac settings (schedule+mode)."""
175
- response = await self .session .get_vehicle_data (
176
- account_id = self .account_id ,
177
- vin = self .vin ,
178
- endpoint = "hvac-settings" ,
179
- )
180
+ response = await self ._get_vehicle_data ("hvac-settings" )
180
181
return cast (
181
182
models .KamereonVehicleHvacSettingsData ,
182
183
response .get_attributes (schemas .KamereonVehicleHvacSettingsDataSchema ),
183
184
)
184
185
185
186
async def get_charge_mode (self ) -> models .KamereonVehicleChargeModeData :
186
187
"""Get vehicle charge mode."""
187
- response = await self .session .get_vehicle_data (
188
- account_id = self .account_id ,
189
- vin = self .vin ,
190
- endpoint = "charge-mode" ,
191
- )
188
+ response = await self ._get_vehicle_data ("charge-mode" )
192
189
return cast (
193
190
models .KamereonVehicleChargeModeData ,
194
191
response .get_attributes (schemas .KamereonVehicleChargeModeDataSchema ),
195
192
)
196
193
197
194
async def get_cockpit (self ) -> models .KamereonVehicleCockpitData :
198
195
"""Get vehicle cockpit."""
199
- response = await self .session .get_vehicle_data (
200
- account_id = self .account_id ,
201
- vin = self .vin ,
202
- endpoint = "cockpit" ,
203
- )
196
+ response = await self ._get_vehicle_data ("cockpit" )
204
197
return cast (
205
198
models .KamereonVehicleCockpitData ,
206
199
response .get_attributes (schemas .KamereonVehicleCockpitDataSchema ),
207
200
)
208
201
209
202
async def get_lock_status (self ) -> models .KamereonVehicleLockStatusData :
210
203
"""Get vehicle lock status."""
211
- response = await self .session .get_vehicle_data (
212
- account_id = self .account_id ,
213
- vin = self .vin ,
214
- endpoint = "lock-status" ,
215
- )
204
+ response = await self ._get_vehicle_data ("lock-status" )
216
205
return cast (
217
206
models .KamereonVehicleLockStatusData ,
218
207
response .get_attributes (schemas .KamereonVehicleLockStatusDataSchema ),
219
208
)
220
209
221
210
async def get_res_state (self ) -> models .KamereonVehicleResStateData :
222
211
"""Get vehicle res state."""
223
- response = await self .session .get_vehicle_data (
224
- account_id = self .account_id ,
225
- vin = self .vin ,
226
- endpoint = "res-state" ,
227
- )
212
+ response = await self ._get_vehicle_data ("res-state" )
228
213
return cast (
229
214
models .KamereonVehicleResStateData ,
230
215
response .get_attributes (schemas .KamereonVehicleResStateDataSchema ),
231
216
)
232
217
233
218
async def get_charging_settings (self ) -> models .KamereonVehicleChargingSettingsData :
234
219
"""Get vehicle charging settings."""
235
- response = await self .session .get_vehicle_data (
236
- account_id = self .account_id ,
237
- vin = self .vin ,
238
- endpoint = "charging-settings" ,
239
- )
220
+ response = await self ._get_vehicle_data ("charging-settings" )
240
221
return cast (
241
222
models .KamereonVehicleChargingSettingsData ,
242
223
response .get_attributes (schemas .KamereonVehicleChargingSettingsDataSchema ),
@@ -246,11 +227,7 @@ async def get_notification_settings(
246
227
self ,
247
228
) -> models .KamereonVehicleNotificationSettingsData :
248
229
"""Get vehicle notification settings."""
249
- response = await self .session .get_vehicle_data (
250
- account_id = self .account_id ,
251
- vin = self .vin ,
252
- endpoint = "notification-settings" ,
253
- )
230
+ response = await self ._get_vehicle_data ("notification-settings" )
254
231
return cast (
255
232
models .KamereonVehicleNotificationSettingsData ,
256
233
response .get_attributes (
0 commit comments