import logging import sys try: from carconnectivity.carconnectivity import CarConnectivity except ImportError: print( "carconnectivity is not installed. Run: " "pip install carconnectivity carconnectivity-connector-volkswagen", file=sys.stderr, ) sys.exit(1) log = logging.getLogger(__name__) def connect(username: str, password: str) -> CarConnectivity: config = { "carConnectivity": { "connectors": [ { "type": "volkswagen", "config": { "username": username, "password": password, }, } ] } } cc = CarConnectivity(config=config) cc.startup() cc.fetch_all() return cc def select_vehicle(cc: CarConnectivity, vin: str | None): """Return (vehicle, error_message). error_message is None on success.""" vehicles = list(cc.get_garage().list_vehicles()) if not vehicles: return None, "No vehicles found in this CarConnectivity account" if vin: vehicle = next((v for v in vehicles if v.vin.value == vin), None) if not vehicle: available = [v.vin.value for v in vehicles] return None, f"VIN {vin} not found. Available: {available}" return vehicle, None return vehicles[0], None def update(cc: CarConnectivity) -> None: cc.fetch_all()