protected bool IsAtChargingLocation(long vehicleId) { Log.Debug(TAG, $"Enter: IsAtChargingLocation({vehicleId})"); Log.Debug(TAG, "GetDriveState..."); var driveState = TeslaAPI.GetDriveState(vehicleId).Result; var chargingLocation = new Location("Charging Location") { Latitude = this.ChargingLocation.Latitude, Longitude = this.ChargingLocation.Longitude }; var vehicleLocation = new Location("Vehicle Location") { Latitude = driveState.latitude.Value, Longitude = driveState.longitude.Value }; var currentDistance = chargingLocation.DistanceTo(vehicleLocation); // in meters. Log.Debug(TAG, $"currentDistance: {currentDistance}"); Log.Debug(TAG, $"Exit: IsAtChargingLocation({vehicleId})"); return(currentDistance <= this.DistanceFromChargingLocation); }
protected void ValidateAccessToken() { Log.Debug(TAG, "Enter: ValidateAccessToken()"); Log.Debug(TAG, $"AccessToken: {this.AccessToken}"); Log.Debug(TAG, $"AccessTokenExpiration: {this.AccessTokenExpiration}"); if (String.IsNullOrEmpty(this.AccessToken) || this.AccessTokenExpiration <= DateTime.Now) { // No valid access token. var email = PrefHelper.GetPrefString(Constants.PrefKeys.USER_EMAIL); var password = PrefHelper.GetPrefString(Constants.PrefKeys.USER_PASSWORD); Log.Debug(TAG, "GetAccessToken..."); var accessToken = TeslaAPI.GetAccessToken(email, password).Result; if (accessToken != null) { PrefHelper.SetPref(Constants.PrefKeys.USER_EMAIL, email); PrefHelper.SetPref(Constants.PrefKeys.USER_PASSWORD, password); this.AccessToken = accessToken.Token; this.AccessTokenExpiration = accessToken.ExpirationDate; Log.Debug(TAG, $"AccessToken: {this.AccessToken}"); Log.Debug(TAG, $"AccessTokenExpiration: {this.AccessTokenExpiration}"); } } Log.Debug(TAG, "Exit: ValidateAccessToken()"); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); this._prefHelper = new PrefHelper(this.ApplicationContext); this._teslaAPI = new TeslaAPI(this.AccessToken); }