public LoginPage(TeslaService teslaService, IProfileService profileService, ITeslaAPIWrapper teslaAPIWrapper) { TeslaService = teslaService; ProfileService = profileService; TeslaAPIWrapper = teslaAPIWrapper; Email = new Entry { Placeholder = "Email", Keyboard = Keyboard.Numeric, }; Email.TextChanged += TextChanged; Password = new Entry { Placeholder = "Password", Keyboard = Keyboard.Numeric, }; Password.TextChanged += TextChanged; LoginButton = new Button { Text = "Login", IsEnabled = false, }; LoginButton.Clicked += Button_Clicked; Content = new StackLayout { Children = { Email, Password, LoginButton, }, }; }
public TeslaService(ITeslaCache cache, ITeslaAPIWrapper teslaAPI) { Cache = cache; TeslaAPI = teslaAPI; var cachedAuth = cache.GetAuthentication(); if (cachedAuth != null) { teslaAPI.SetBearerToken(cachedAuth.AccessToken); } }
public ExecuteActionPage(Profile profile, TeslaVehicle vehicle, ITeslaAPIWrapper teslaAPIWrapper) { CurrentActionLabel = new Label { HorizontalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, }; Content = CurrentActionLabel; Profile = profile; Vehicle = vehicle; TeslaAPIWrapper = teslaAPIWrapper; }
public VehicleNavigation(TeslaService teslaService, IProfileService profileService, ITeslaAPIWrapper teslaAPIWrapper) { TeslaService = teslaService; ProfileService = profileService; TeslaAPIWrapper = teslaAPIWrapper; NavigationPage.SetHasNavigationBar(this, false); Children.Add(new LoadingPage()); var thread = new Thread(new ThreadStart(Setup)) { IsBackground = true }; thread.Start(); }
public static async Task Execute(this VehicleAction action, TeslaVehicle vehicle, ITeslaAPIWrapper teslaApi) { LogUtil.Debug($"Start Executing {action.Type.GetDescription()}"); // TODO remaining actions switch (action.Type) { case VehicleActionType.WakeUp: await teslaApi.WakeUp(vehicle); break; case VehicleActionType.ClimateACStart: await teslaApi.StartAutoConditioning(vehicle); break; case VehicleActionType.ClimateACStop: await teslaApi.StopAutoConditioning(vehicle); break; case VehicleActionType.ClimateSetTemps: var driverTemp = (double)action.Params["driver_temp"]; var passengerTemp = (double)action.Params["passenger_temp"]; await teslaApi.SetTemps(vehicle, driverTemp, passengerTemp); break; case VehicleActionType.ClimateHeatedSeat: var heater = (int)action.Params["heater"]; var level = (int)action.Params["level"]; await teslaApi.SeatHeaterRequest(vehicle, heater, level); break; case VehicleActionType.ClimateHeatedSteeringWheel: var on = (bool)action.Params["on"]; await teslaApi.SteeringWheelHeaterRequest(vehicle, on); break; case VehicleActionType.ChargingStart: await teslaApi.ChargeStart(vehicle); break; case VehicleActionType.ChargingStop: await teslaApi.ChargeStop(vehicle); break; case VehicleActionType.ChargingSetLimit: var percent = (int)action.Params["percent"]; await teslaApi.SetChargeLimit(vehicle, percent); break; case VehicleActionType.ChargingOpenPort: await teslaApi.ChargePortOpen(vehicle); break; case VehicleActionType.ChargingClosePort: await teslaApi.ChargePortClose(vehicle); break; case VehicleActionType.ControlsDoorsLock: await teslaApi.DoorLock(vehicle); break; case VehicleActionType.ControlsDoorsUnlock: await teslaApi.DoorUnlock(vehicle); break; case VehicleActionType.ControlsFlashLights: await teslaApi.FlashLights(vehicle); break; case VehicleActionType.ControlsHonkHorn: await teslaApi.HonkHorn(vehicle); break; case VehicleActionType.ControlsFrontTrunk: await teslaApi.ActuateTrunk(vehicle, "front"); break; case VehicleActionType.ControlsRearTrunk: await teslaApi.ActuateTrunk(vehicle, "rear"); break; case VehicleActionType.ControlsSunRoof: var state = (string)action.Params["state"]; await teslaApi.SunRoofControl(vehicle, state); break; case VehicleActionType.RemoteStartDrive: case VehicleActionType.SpeedLimitActivate: case VehicleActionType.SpeedLimitClearPin: case VehicleActionType.SpeedLimitDeactivate: case VehicleActionType.SpeedLimitSet: case VehicleActionType.ValetModeResetPin: case VehicleActionType.ValetModeSet: Thread.Sleep(500); break; } LogUtil.Debug($"Finished Executing {action.Type.GetDescription()}"); }
public VehicleOverviewPage(TeslaVehicle vehicle, IProfileService profileService, ITeslaAPIWrapper teslaAPIWrapper) { Content = new StackLayout { VerticalOptions = LayoutOptions.Center, Children = { new Label { FontSize = 20, HorizontalTextAlignment = TextAlignment.Center, Text = vehicle.Name, }, }, GestureRecognizers = { new TapGestureRecognizer { Command = new Command(async() => { await Navigation.PushAsync(new ProfilesListPage(vehicle, profileService, teslaAPIWrapper)); }), } } }; }
public ProfilesListPage(TeslaVehicle vehicle, IProfileService profileService, ITeslaAPIWrapper teslaAPIWrapper) { NavigationPage.SetHasNavigationBar(this, false); var listView = new CircleListView { Header = UIUtil.CreateHeaderLabel(vehicle.Name), ItemTemplate = new DataTemplate(() => { Label nameLabel = new Label { HeightRequest = 120, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, }; nameLabel.SetBinding(Label.TextProperty, "Name"); return(new ViewCell { View = new StackLayout { Children = { nameLabel, } } }); }), }; listView.ItemTapped += async(sender, e) => { var binder = (ProfileBinder)e.Item; await Navigation.PushAsync(new ProfileActionPage(binder.Profile, vehicle, profileService, teslaAPIWrapper)); }; ActionButton = new ActionButtonItem { Text = "Create", Command = new Command(async() => { await Navigation.PushAsync(new EditProfilePage(profileService)); }) }; Content = listView; Disposable = profileService .GetProfiles() .Subscribe(updatedList => { LogUtil.Debug("New profiles list count = " + updatedList.Count); listView.ItemsSource = updatedList.Select(p => new ProfileBinder(p)); }); }
public ProfileActionPage(Profile profile, TeslaVehicle teslaVehicle, IProfileService profileService, ITeslaAPIWrapper teslaAPIWrapper) { NavigationPage.SetHasNavigationBar(this, false); var listView = new CircleListView { Header = UIUtil.CreateHeaderLabel(profile.Name), ItemsSource = new List <string> { "Run", "Edit", "Delete" }, }; listView.ItemTapped += async(sender, e) => { switch (e.Item) { case "Run": await Navigation.PushAsync(new ExecuteActionPage(profile, teslaVehicle, teslaAPIWrapper)); break; case "Edit": await Navigation.PushAsync(new EditProfilePage(profile, profileService)); // Remove this page. After editing the action this list should be gone. Navigation.RemovePage(Navigation.NavigationStack[Navigation.NavigationStack.Count - 2]); break; case "Delete": await profileService.DeleteProfileAsync(profile); await Navigation.PopAsync(); break; default: break; } }; Content = listView; }