import garth from src.utils.helpers import setup_logger from .auth import AuthMixin from .data import DataMixin logger = setup_logger(__name__) class GarminClient(AuthMixin, DataMixin): def __init__(self, username: str = None, password: str = None, is_china: bool = False): self.username = username self.password = password self.is_china = is_china self.garmin_client = None self.is_connected = False logger.debug(f"Initializing GarminClient for user: {username}, is_china: {is_china}") if is_china: logger.debug("Configuring garth for China domain") garth.configure(domain="garmin.cn") if username and password: logger.info(f"GarminClient initialized for user: {username}") else: logger.debug("GarminClient initialized without credentials") def check_connection(self) -> bool: """Check if the connection to Garmin is still valid.""" try: profile = self.garmin_client.get_full_name() if self.garmin_client else None return profile is not None except: self.is_connected = False return False def get_profile_info(self): """Get user profile information.""" if not self.is_connected: self.login() if self.is_connected: return garth.UserProfile.get() return None