Esempio n. 1
0
        public async Task <TessApiResult> SetTemps(double driver, double passenger)
        {
            string drvStr = TessTools.GetDoubleAsString(driver);
            string pasStr = TessTools.GetDoubleAsString(passenger);

            string cmdTxt = $"driver_temp={drvStr}&passenger_temp={pasStr}";

            return(await SendCommand("set_temps", cmdTxt));
        }
Esempio n. 2
0
        private void HandleLoginSuccess()
        {
            LoginResponse = tessApiLogin.LoginResponse;
            if (String.IsNullOrEmpty(LoginResponse?.access_token))
            {
                throw new Exception("access_token LEER!");
            }
            TessTools.SaveResponse(LoginResponse, null, true);

            tessApiLogin = null; // brauchen wir jetzt nicht mehr!
            myCarId      = null; // Can change for other user! Need to reset after login.
        }
Esempio n. 3
0
        public async Task LoadLogin()
        {
            LoginResponse = TessTools.LoadResponse <LoginResponse>(out _, true);

            //if ( true ) {
            //    if ( tessApiLogin == null ) {
            //        tessApiLogin = new TessApiLogin();
            //        tessApiLogin.LoginResponse = LoginResponse;
            //    }
            //    await tessApiLogin.UpdateTeslaTokenFromRefreshToken();
            //    //LoginResponse tmpLoginResponse = await TessApiLogin.UpdateTeslaTokenFromRefreshToken(LoginResponse);
            //    //if ( tmpLoginResponse != null ) LoginResponse = tmpLoginResponse;
            //    //// todo save?
            //}
        }
Esempio n. 4
0
        private async Task <TessApiResult> SendCommand(string command, string commandText = null)
        {
            try {
                string url    = $"https://owner-api.teslamotors.com/api/1/vehicles/{myCarId.Value}/command/" + command;
                string result = await CallUrl(url, "POST", true, commandText);

                CommandResult cr = SerializeTool.DeSerializeJson <CommandResult>(result);
                TessTools.SaveResponse(cr, command);
                return(new TessApiResult(cr));
            }
            catch (Exception ex) {
                Log.Error("MyTess.SendCommand: " + command, ex);
                return(new TessApiResult(ex));
            }
        }
Esempio n. 5
0
        public async Task <TessApiResult> WakeUp()
        {
            this.MyCarData = null;
            string url = $"https://owner-api.teslamotors.com/api/1/vehicles/{myCarId.Value}/wake_up";

            try {
                string result = await CallUrl(url, "POST");

                CarDataResponse pr = SerializeTool.DeSerializeJson <CarDataResponse>(result);
                TessTools.SaveResponse(pr);
                MyCarData = pr.response;

                return(new TessApiResult());
            }
            catch (Exception ex) {
                return(new TessApiResult(ex));
            }
        }
Esempio n. 6
0
        public async Task <TessApiResult> ListProducts(bool loadFromDisk)
        {
            this.MyCar     = null;
            this.MyCarData = null;

            try {
                ProductResponse pr;
                if (loadFromDisk)
                {
                    pr = TessTools.LoadResponse <ProductResponse>(out _);
                }
                else
                {
                    // Optional https://owner-api.teslamotors.com/api/1/vehicles
                    string url    = "https://owner-api.teslamotors.com/api/1/products/";
                    string result = await CallUrl(url, "GET");

                    pr = SerializeTool.DeSerializeJson <ProductResponse>(result);
                    TessTools.SaveResponse(pr);
                }

                ProductList = pr.response;

                if (myCarId.HasValue)
                {
                    foreach (Product p in pr.response)
                    {
                        if (p.id == myCarId)
                        {
                            MyCar = p;
                        }
                    }
                }

                return(new TessApiResult());
            }
            catch (Exception ex) {
                Log.Error("MyTess.ListProducts", ex);
                return(new TessApiResult(ex));
            }
        }
Esempio n. 7
0
        public async Task <TessApiResult> GetCarInfo(bool loadFromDisk)
        {
            this.MyCarData = null;
            try {
                CarDataResponse cdr = null;
                if (loadFromDisk)
                {
                    cdr = TessTools.LoadResponse <CarDataResponse>(out DiskDataDate);
                    Log.Debug("GetCarInfo - loadFromDisk cdr Null:" + (cdr == null));
                    if (cdr != null)
                    {
                        MyCarData = cdr.response;
                        return(new TessApiResult());
                    }
                }

                if (MyCar == null)
                {
                    return(new TessApiResult(false, "No Car Data"));
                }

                if (!loadFromDisk)
                {
                    string url    = $"https://owner-api.teslamotors.com/api/1/vehicles/{myCarId.Value}/vehicle_data";
                    string result = await CallUrl(url, "GET");

                    cdr = SerializeTool.DeSerializeJson <CarDataResponse>(result);
                }

                MyCarData = cdr?.response;
                if (cdr != null)
                {
                    TessTools.SaveResponse(cdr);
                }
                return(new TessApiResult());
            }
            catch (Exception ex) {
                Log.Error("MyTess.GetCarInfo", ex);
                return(new TessApiResult(ex));
            }
        }