we_connect.py now only handles WeConnect login and vehicle selection. All extract_*() functions, ALL_DOMAINS, and collect_snapshot() live in data_model.py alongside the store and value helpers. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
36 lines
1010 B
Python
36 lines
1010 B
Python
import logging
|
|
import sys
|
|
|
|
try:
|
|
from weconnect import weconnect
|
|
except ImportError:
|
|
print("weconnect is not installed. Run: pip install weconnect", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
def connect(username: str, password: str):
|
|
wc = weconnect.WeConnect(
|
|
username=username,
|
|
password=password,
|
|
updateAfterLogin=False,
|
|
loginOnInit=True,
|
|
)
|
|
wc.login()
|
|
wc.update()
|
|
return wc
|
|
|
|
|
|
def select_vehicle(wc, vin: str | None):
|
|
"""Return (vehicle, error_message). error_message is None on success."""
|
|
vehicles = list(wc.vehicles.values())
|
|
if not vehicles:
|
|
return None, "No vehicles found in this WeConnect 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 |