Esempio n. 1
0
        public void RunObservableUpdate()
        {
            using (var nest = new NestConnection())
            {
                nest.setInitialConnectionProps();

                if (nest.isAccessNotNull())
                {
                    nest.connectNestData();
                }
            }
        }
        public override string postBackProc(string page, string data, string user, int userRights)
        {
            System.Collections.Specialized.NameValueCollection parts = null;
            parts = HttpUtility.ParseQueryString(data);

            Console.WriteLine(data);

            string id = parts["id"];

            if (parts["pin_code"] != null)
            {
                pin_code = parts["pin_code"];
                Console.WriteLine(pin_code);
            }
            if (parts["id"] != null && parts["id"].Contains("access_button"))
            {
                using (var nest = new NestConnection())
                {
                    if (nest.retrieveAccess(pin_code))
                    {
                        pageCommands.Add("popmessage", "Successfully reset Access Token");
                    }
                    else
                    {
                        pageCommands.Add("popmessage", "Failed to reset Access Token");
                    }
                }
            }
            if (id == "devices_button")
            {
                using (var nest = new NestConnection())
                {
                    nest.setInitialConnectionProps();
                    if (nest.isAccessNotNull())
                    {
                        using (var nestData = nest.getNestData())
                        {
                            Util.Find_Create_Devices(nestData.Devices, true);
                            Util.Find_Create_Structures(nestData.Structures, true);
                        }
                    }

                    else
                    {
                        Util.Log("Access Token is null", Util.LogType.LOG_TYPE_ERROR);
                    }
                }
            }

            return(base.postBackProc(page, data, user, userRights));
        }
Esempio n. 3
0
        private void updateStatusValues()
        {
            try
            {
                if (!observeRunning) // Set True in NestConnection.connectNestData()
                {
                    observeRunning = true;
                    System.Threading.Tasks.Task.Factory.StartNew(() => RunObservableUpdate());
                }
                if (!running)
                {
                    using (var nest = new NestConnection())
                    {
                        running = true;
                        nest.setInitialConnectionProps();
                        if (nest.isAccessNotNull())
                        {
                            using (var nestData = nest.getNestData())
                            {
                                Util.Find_Create_Devices(nestData.Devices, false);
                                Util.Find_Create_Structures(nestData.Structures, false);
                            }
                        }

                        else
                        {
                            Util.Log("Access Token is null", Util.LogType.LOG_TYPE_ERROR);
                        }
                        running = false;
                    }
                }
            }
            catch (Exception ex)
            {
                //Console.WriteLine("Failed: No API Key?");
                Util.Log(ex.ToString(), Util.LogType.LOG_TYPE_ERROR);
                System.IO.File.WriteAllText(@"Data/HSPI_Nest_Thermostat_and_Camera_Plugin/debug.txt", ex.ToString());
                if (ex.ToString().Contains("connectNestData"))
                {
                    observeRunning = false;
                }
                running = false;
            }
        }