4040class Vehicle :
4141 """Vehicle contains the state of sensors and methods for interacting with the car."""
4242
43- # Single source of truth for all supported services
44- SUPPORTED_SERVICES = [
45- Services .ACCESS ,
46- Services .AUXILIARY_HEATING ,
47- Services .BATTERY_CHARGING_CARE ,
48- Services .BATTERY_SUPPORT ,
49- Services .CHARGING ,
50- Services .CLIMATISATION ,
51- Services .CLIMATISATION_TIMERS ,
52- Services .DEPARTURE_PROFILES ,
53- Services .DEPARTURE_TIMERS ,
54- Services .FUEL_STATUS ,
55- Services .HONK_AND_FLASH ,
56- Services .MEASUREMENTS ,
57- Services .PARKING_POSITION ,
58- Services .READINESS ,
59- Services .TRIP_STATISTICS ,
60- Services .USER_CAPABILITIES ,
61- Services .VEHICLE_LIGHTS ,
62- Services .VEHICLE_HEALTH_INSPECTION ,
63- ]
64-
65- # Services that should not be queried during regular updates
66- UPDATE_EXCLUDED_SERVICES = [
67- Services .PARKING_POSITION , # Has dedicated method call
68- Services .TRIP_STATISTICS , # Has dedicated method calls
69- Services .HONK_AND_FLASH , # Action service, not data service
70- ]
71-
72- # Service replacements - when fetching data, replace key with value
73- SERVICE_FETCH_REPLACEMENTS = {
74- Services .AUXILIARY_HEATING : Services .CLIMATISATION ,
75- }
76-
77- # Services that must always be included in updates regardless of active status
78- MANDATORY_FETCH_SERVICES = [
79- Services .ACCESS ,
80- ]
81-
8243 def __init__ (self , conn , url ) -> None :
8344 """Initialize the Vehicle with default values."""
8445 self ._connection = conn
@@ -97,12 +58,24 @@ def __init__(self, conn, url) -> None:
9758 }
9859
9960 # API Endpoints that might be enabled for car (that we support)
100- # Initialize from SUPPORTED_SERVICES constant
10161 self ._services : dict [str , dict [str , object ]] = {
102- service : {"active" : False } for service in self .SUPPORTED_SERVICES
62+ Services .ACCESS : {"active" : False },
63+ Services .BATTERY_CHARGING_CARE : {"active" : False },
64+ Services .BATTERY_SUPPORT : {"active" : False },
65+ Services .CHARGING : {"active" : False },
66+ Services .CLIMATISATION : {"active" : False },
67+ Services .CLIMATISATION_TIMERS : {"active" : False },
68+ Services .DEPARTURE_PROFILES : {"active" : False },
69+ Services .DEPARTURE_TIMERS : {"active" : False },
70+ Services .FUEL_STATUS : {"active" : False },
71+ Services .HONK_AND_FLASH : {"active" : False },
72+ Services .MEASUREMENTS : {"active" : False },
73+ Services .PARKING_POSITION : {"active" : False },
74+ Services .READINESS : {"active" : False },
75+ Services .TRIP_STATISTICS : {"active" : False },
76+ Services .USER_CAPABILITIES : {"active" : False },
77+ Services .PARAMETERS : {},
10378 }
104- # Add PARAMETERS as special case
105- self ._services [Services .PARAMETERS ] = {}
10679
10780 def _in_progress (self , topic : str , unknown_offset : int = 0 ) -> bool :
10881 """Check if request is already in progress."""
@@ -224,47 +197,31 @@ async def update(self) -> None:
224197 if not self ._discovered :
225198 await self .discover ()
226199 if not self .deactivated :
227- # Build list of active services to fetch
228- active_services = [
229- service_name
230- for service_name in self .SUPPORTED_SERVICES
231- if service_name not in self .UPDATE_EXCLUDED_SERVICES
232- and self ._services .get (service_name , {}).get ("active" , False )
233- ]
234-
235- # Add mandatory services that must always be fetched
236- for service in self .MANDATORY_FETCH_SERVICES :
237- if (
238- service not in active_services
239- and service not in self .UPDATE_EXCLUDED_SERVICES
240- ):
241- active_services .append (service )
242-
243- # Apply service fetch replacements
244- for original , replacement in self .SERVICE_FETCH_REPLACEMENTS .items ():
245- if original in active_services :
246- active_services .remove (original )
247- if replacement not in active_services :
248- active_services .append (replacement )
249-
250- # Only fetch if there are active services
251- tasks = [self .get_vehicle ()]
252- if active_services :
253- tasks .insert (0 , self .get_selectivestatus (active_services ))
254-
255- # Add conditional service calls
256- if self ._services .get (Services .PARKING_POSITION , {}).get ("active" , False ):
257- tasks .append (self .get_parkingposition ())
258- if self ._services .get (Services .TRIP_STATISTICS , {}).get ("active" , False ):
259- tasks .extend (
200+ await asyncio .gather (
201+ self .get_selectivestatus (
260202 [
261- self .get_trip_last (),
262- self .get_trip_refuel (),
263- self .get_trip_longterm (),
203+ Services .ACCESS ,
204+ Services .BATTERY_CHARGING_CARE ,
205+ Services .BATTERY_SUPPORT ,
206+ Services .CHARGING ,
207+ Services .CLIMATISATION ,
208+ Services .CLIMATISATION_TIMERS ,
209+ Services .DEPARTURE_PROFILES ,
210+ Services .DEPARTURE_TIMERS ,
211+ Services .FUEL_STATUS ,
212+ Services .MEASUREMENTS ,
213+ Services .READINESS ,
214+ Services .VEHICLE_LIGHTS ,
215+ Services .VEHICLE_HEALTH_INSPECTION ,
216+ Services .USER_CAPABILITIES ,
264217 ]
265- )
266-
267- await asyncio .gather (* tasks )
218+ ),
219+ self .get_vehicle (),
220+ self .get_parkingposition (),
221+ self .get_trip_last (),
222+ self .get_trip_refuel (),
223+ self .get_trip_longterm (),
224+ )
268225 await asyncio .gather (self .get_service_status ())
269226 else :
270227 _LOGGER .info ("Vehicle with VIN %s is deactivated" , self .vin )
0 commit comments