示例#1
0
 private void updateStatusValues()
 {
     RanAt = DateTime.Now;
     //   Util.Log("updateStatusValues", Util.LogType.LOG_TYPE_WARNING);
     running = true;
     try
     {
         using (var rachio = new RachioConnection())
         {
             if (rachio.HasAccessToken())
             {
                 Util.Find_Create_Devices(rachio, false);
             }
             else
             {
                 Util.Log("No Access Token saved", Util.LogType.LOG_TYPE_WARNING);
             }
         }
     }
     catch (Exception ex)
     {
         Util.Log(ex.ToString(), Util.LogType.LOG_TYPE_ERROR);
         System.IO.File.WriteAllText(@"Data/HSPI_Rachio_Irrigation_Plugin/debug.txt", ex.ToString());  // Write Exception data to debug.txt
     }
     running = false;
 }
示例#2
0
        public OptionsPage(string pagename) : base(pagename)
        {
            string json = Util.hs.GetINISetting("RACHIO", "login", "", Util.IFACE_NAME + ".ini");

            using (Login Login = RachioConnection.getLoginInfo(json))
            {
                if (Login != null)
                {
                    this.apiKey         = Login.accessToken;
                    this.unitType       = Login.units;
                    this.updateInterval = Login.updateFrequency;
                    this.loggingType    = Login.loggingLevel;
                    ZoneChecks          = new List <bool>();

                    if (Login.ZoneView == null)
                    {
                        for (int i = 0; i < 16; i++)
                        {
                            ZoneChecks.Add(true);
                        }
                    }
                    else
                    {
                        ZoneChecks = Login.ZoneView;
                    }
                }
            }
        }
示例#3
0
 private void updateStatusValues()
 {
     running = true;
     try
     {
         using (var rachio = new RachioConnection())
         {
             if (rachio.HasAccessToken())
             {
                 Util.Find_Create_Devices(rachio);
             }
             else
             {
                 Util.Log("No Access Token saved", Util.LogType.LOG_TYPE_WARNING);
             }
         }
     }
     catch (Exception ex)
     {
         Util.Log(ex.ToString(), Util.LogType.LOG_TYPE_ERROR);
         System.IO.File.WriteAllText(@"Data/hspi_rachiosiid/debug.txt", ex.ToString());  // Write Exception data to debug.txt
     }
     running = false;
 }
示例#4
0
        public void RachioControls(List <HomeSeerAPI.CAPI.CAPIControl> colSend)
        {
            foreach (CAPI.CAPIControl CC in colSend)
            {
                try
                {
                    Util.Log("SetIOMulti set value: " + CC.ControlValue.ToString() + "->ref:" + CC.Ref.ToString() + "-" + CC.ControlType + "-" + CC.Label, Util.LogType.LOG_TYPE_INFO);
                    using (var rachio = new RachioConnection())
                    {
                        DeviceClass dv = (DeviceClass)Util.hs.GetDeviceByRef(CC.Ref);
                        string      name;
                        string      type;
                        string      id = Util.GetDeviceKeys(dv, out name, out type);


                        //if (CC.ControlType == Enums.CAPIControlType.TextBox_Number)
                        //{
                        // Zone Controls
                        if (CC.ControlValue > 0 && CC.ControlValue <= 180 && name == "Control")
                        {
                            Util.Log("Zone Running " + CC.ControlValue + " Minutes", Util.LogType.LOG_TYPE_INFO);


                            rachio.setApiJson("{\"id\" : \"" + id + "\", \"duration\" : " + CC.ControlValue * 60 + "}", "zone/start");
                        }
                        // Schedule Rule Controls
                        if (CC.ControlValue > 0 && CC.ControlValue <= 180 && name == "Seasonal Adjustment")
                        {
                            rachio.setApiJson("{\"id\" : \"" + id + "\", \"adjustment\" : " + CC.ControlValue + "}", "schedulerule/seasonal_adjustment");
                        }
                        //}
                        // Stop Watering Button
                        //if (CC.ControlType == Enums.CAPIControlType.Button)
                        //{
                        //There is not zone/stop_water
                        if (name == "Watering State")
                        {
                            rachio.setApiJson("{\"id\" : \"" + id + "\"}", "device/stop_water");
                        }

                        //stopping a zone may just be starting a zone with time=0 (don't see a zone stop method)
                        if (CC.Label.Contains("Off"))
                        {
                            rachio.setApiJson("{\"id\" : \"" + id + "\", \"duration\":0}", "zone/start");
                        }
                        //}

                        //if (CC.ControlType == Enums.CAPIControlType.Single_Text_from_List)
                        //{
                        // Rain Delay
                        if (name == "Rain Delay")
                        {
                            rachio.setApiJson("{\"id\" : \"" + id + "\", \"duration\" : " + CC.ControlValue * 3600 * 24 + "}", "device/rain_delay");
                        }
                        // Device Status
                        if (name == "Status" && type == "Device")
                        {
                            if (CC.ControlValue == 1)
                            {
                                rachio.setApiJson("{\"id\" : \"" + id + "\"}", "device/on");
                            }
                            if (CC.ControlValue == 0)
                            {
                                rachio.setApiJson("{\"id\" : \"" + id + "\"}", "device/off");
                            }
                        }
                        //}
                    }
                }
                catch (Exception e)
                {
                    Util.Log(e.ToString(), Util.LogType.LOG_TYPE_ERROR);
                }
            }
            //wait 5 seconds and then do this
            Thread.Sleep(5000);
            if (!running && (DateTime.Now - RanAt).TotalSeconds > 5)
            {
                updateStatusValues();
            }
        }
示例#5
0
        public void RachioControls(List <HomeSeerAPI.CAPI.CAPIControl> colSend)
        {
            foreach (CAPI.CAPIControl CC in colSend)
            {
                try
                {
                    Util.Log("SetIOMulti set value: " + CC.ControlValue.ToString() + "->ref:" + CC.Ref.ToString() + "-" + CC.ControlType + "-" + CC.Label, Util.LogType.LOG_TYPE_ERROR);
                    using (var rachio = new RachioConnection())
                    {
                        DeviceClass dv = (DeviceClass)Util.hs.GetDeviceByRef(CC.Ref);
                        string      name;
                        string      type;
                        string      id = Util.GetDeviceKeys(dv, out name, out type);


                        //if (CC.ControlType == Enums.CAPIControlType.TextBox_Number)
                        //{
                        // Zone Controls
                        if (CC.ControlValue > 0 && CC.ControlValue <= 180 && name == "Control")
                        {
                            Console.WriteLine("Zone Running " + CC.ControlValue + " Minutes");
                            rachio.setApiJson("{\"id\" : \"" + id + "\", \"duration\" : " + CC.ControlValue * 60 + "}", "zone/start");
                        }
                        // Schedule Rule Controls
                        if (CC.ControlValue > 0 && CC.ControlValue <= 180 && name == "Seasonal Adjustment")
                        {
                            rachio.setApiJson("{\"id\" : \"" + id + "\", \"adjustment\" : " + CC.ControlValue + "}", "schedulerule/seasonal_adjustment");
                        }
                        //}
                        // Stop Watering Button
                        //if (CC.ControlType == Enums.CAPIControlType.Button)
                        //{
                        if (name == "Watering State" || CC.Label.Contains("Off"))
                        {
                            using (var person = rachio.getPerson())
                            {
                                rachio.setApiJson("{\"id\" : \"" + person.devices[0].id + "\"}", "device/stop_water");
                            }
                        }
                        //}

                        //if (CC.ControlType == Enums.CAPIControlType.Single_Text_from_List)
                        //{
                        // Rain Delay
                        if (name == "Rain Delay")
                        {
                            rachio.setApiJson("{\"id\" : \"" + id + "\", \"duration\" : " + CC.ControlValue * 3600 * 24 + "}", "device/rain_delay");
                        }
                        // Device Status
                        if (name == "Status" && type == "Device")
                        {
                            if (CC.ControlValue == 1)
                            {
                                rachio.setApiJson("{\"id\" : \"" + id + "\"}", "device/on");
                            }
                            if (CC.ControlValue == 0)
                            {
                                rachio.setApiJson("{\"id\" : \"" + id + "\"}", "device/off");
                            }
                        }
                        //}
                    }
                }
                catch (Exception e)
                {
                    Util.Log(e.ToString(), Util.LogType.LOG_TYPE_ERROR);
                }
            }
            updateStatusValues();
        }
示例#6
0
        // Handles any controls on the Options Page
        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 (id == "devices_button")
            {
                using (var rachio = new RachioConnection())
                {
                    if (rachio.HasAccessToken())
                    {
                        Util.Find_Create_Devices(rachio);
                    }
                    else
                    {
                        Util.Log("No Access Token saved", Util.LogType.LOG_TYPE_WARNING);
                    }
                }
            }
            else
            {
                if (parts["APIToken"] != null)
                {
                    Console.WriteLine("api");

                    apiKey = parts["APIToken"];
                    Console.WriteLine(apiKey);
                }
                Console.WriteLine("1");
                if (id == "unitType")
                {
                    if (data.Contains("1"))
                    {
                        unitType = "US";
                    }
                    else
                    {
                        unitType = "METRIC";
                    }
                }
                Console.WriteLine("2");
                if (id == "updateInterval")
                {
                    updateInterval = Int16.Parse(data.Substring(33));
                    Console.WriteLine(updateInterval + " minute update interval");
                    HSPI.test_timer.Interval = 60000 * updateInterval;
                    Console.WriteLine("Time interval set to " + HSPI.test_timer.Interval / 1000 + " seconds");
                }
                Console.WriteLine("3");
                if (id == "loggingType")
                {
                    if (data == "Off")
                    {
                        loggingType = "Off";
                    }
                    else
                    {
                        loggingType = "Debug";
                    }
                }
                Console.WriteLine("4");
                if (data.Contains("ZoneCheck"))
                {
                    if (id.Contains("ZoneCheck"))
                    {
                        string zString = data.Split('=')[0].Substring(9);
                        int    zNum    = Int16.Parse(zString);
                        if (data.Contains("unchecked"))
                        {
                            ZoneChecks[zNum - 1] = false;
                        }
                        else
                        {
                            ZoneChecks[zNum - 1] = true;
                        }
                    }
                }
                try
                {
                    Console.WriteLine("5");
                    using (var login = new Login(apiKey, unitType, updateInterval, loggingType, ZoneChecks))
                    {
                        string json = JsonConvert.SerializeObject(login);
                        Console.WriteLine(json);
                        Util.hs.SaveINISetting("RACHIO", "login", json, Util.IFACE_NAME + ".ini");
                        Console.WriteLine("Saved Preferences");
                    }
                    return(base.postBackProc(page, data, user, userRights));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace);
                }
            }
            return(null);
        }