Пример #1
0
        public void Update()
        {
            //GET Control page
            System.Net.HttpWebRequest  request;
            System.Net.HttpWebResponse response;
            StreamReader streamReader;
            String       responseString;

            request                 = (HttpWebRequest)System.Net.HttpWebRequest.Create(Account.DeviceControlURL + ID);
            request.KeepAlive       = true;
            request.CookieContainer = Account.Login();
            request.Method          = "GET";
            request.ContentType     = "application/x-www-form-urlencoded";
            request.UserAgent       = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36";

            response       = (HttpWebResponse)request.GetResponse();
            streamReader   = new StreamReader(response.GetResponseStream());
            responseString = streamReader.ReadToEnd();
            response.Close();

            Tools.Log(responseString);

            // pull out data
            CoolSetPoint = (int)double.Parse(Tools.Parse(responseString, "coolSetpoint, ", ");"));
            //Tools.Log( "coolSetPoint=" + CoolSetPoint );
            HeatSetPoint = (int)double.Parse(Tools.Parse(responseString, "heatSetpoint, ", ");"));
            //Tools.Log( "heatSetPoint=" + HeatSetPoint );
            Temperature = Tools.Parse(responseString, "dispTemperature, ", ");");
            //Tools.Log( "temperature=" + Temperature );

            SystemSwitch = (SystemSwitchEnum)int.Parse(Tools.Parse(responseString, "systemSwitchPosition, ", ");"));
            //Tools.Log( "SystemSwitch=" + SystemSwitch.ToString() );

            Schedule = (ScheduleEnum)int.Parse(Tools.Parse(responseString, "statusHeat, ", ");"));
            //Tools.Log( "Schedule=" + Schedule.ToString() );

            if (SystemSwitch == SystemSwitchEnum.Heat)
            {
                NextPeriod = int.Parse(Tools.Parse(responseString, "heatNextPeriod, ", ");"));
                //Tools.Log( "NextPeriod=" + NextPeriod );
            }
            if (SystemSwitch == SystemSwitchEnum.Cool)
            {
                NextPeriod = int.Parse(Tools.Parse(responseString, "coolNextPeriod, ", ");"));
                //Tools.Log( "NextPeriod=" + NextPeriod );
            }
        }
Пример #2
0
/*
 * -- off -> set cool permanent hold heat at 50
 * CoolNextPeriod: null
 * CoolSetpoint: null
 * DeviceID: 416280
 * FanMode: null
 * HeatNextPeriod: null
 * HeatSetpoint: 51
 * StatusCool: 2
 * StatusHeat: 2
 * SystemSwitch: 1
 *
 * --> off
 * CoolNextPeriod: null
 * CoolSetpoint: null
 * DeviceID: 416280
 * FanMode: null
 * HeatNextPeriod: null
 * HeatSetpoint: null
 * StatusCool: null
 * StatusHeat: null
 * SystemSwitch: 2
 *
 * --> heat hold until 8:15 pm
 * CoolNextPeriod: 81
 * CoolSetpoint: null
 * DeviceID: 416280
 * FanMode: null
 * HeatNextPeriod: 81
 * HeatSetpoint: 52
 * StatusCool: 1
 * StatusHeat: 1
 * SystemSwitch: 1
 *
 * --> follow schedule
 * CoolNextPeriod: null
 * CoolSetpoint: 99
 * DeviceID: 416280
 * FanMode: null
 * HeatNextPeriod: null
 * HeatSetpoint: 50
 * StatusCool: 0
 * StatusHeat: 0
 * SystemSwitch: null
 */

        /// <summary>
        /// Control the thermostat
        /// </summary>
        /// <param name="systemSwitch">Off, Heat, Cool</param>
        /// <param name="schedule">FollowSchedule, HoldUntil, PermanentHold</param>
        /// <param name="setPoint">Set poitn for heating or cooling</param>
        /// <param name="holdHour">Hours to hold for. E.g. 2 holds for 2 hours.</param>
        /// <param name="holdMinute">Minutes to hold for in multiples of 15 minutes. E.g. 2 = 30 minutes</param>
        public void Set(SystemSwitchEnum systemSwitch, ScheduleEnum schedule, int setPoint, int nextPeriod)
        {
            System.Net.HttpWebRequest  request;
            System.Net.HttpWebResponse response;
            StreamReader streamReader;
            String       responseString;

            request                 = (HttpWebRequest)System.Net.HttpWebRequest.Create("https://mytotalconnectcomfort.com/portal/Device/SubmitControlScreenChanges");
            request.KeepAlive       = false;
            request.ProtocolVersion = HttpVersion.Version10;
            request.CookieContainer = Account.Login();
            request.Method          = "POST";
            request.Accept          = "application/json, text/javascript, */*";
            request.ContentType     = "application/json; charset=UTF-8";
            request.UserAgent       = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36";
            string postData = "{ \"DeviceID\":" + ID;

            postData += ", \"CoolNextPeriod\":" + ((schedule == ScheduleEnum.HoldUntil) ? nextPeriod.ToString() : "null");
            postData += ", \"CoolSetPoint\":" + ((systemSwitch == SystemSwitchEnum.Cool) ? setPoint.ToString() : "null");
            postData += ", \"FanMode\":null";
            postData += ", \"HeatNextPeriod\":" + ((schedule == ScheduleEnum.HoldUntil) ? nextPeriod.ToString() : "null");
            postData += ", \"HeatSetPoint\":" + ((systemSwitch == SystemSwitchEnum.Heat) ? setPoint.ToString() : "null");
            postData += ", \"StatusCool\":" + (int)schedule;
            postData += ", \"StatusHeat\":" + (int)schedule;
            postData += ", \"SystemSwitch\":" + (int)systemSwitch;
            postData += "}";
            byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(postData);
            request.ContentLength = byteArray.Length;
            System.IO.Stream dataStream = request.GetRequestStream();
            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();

            response       = (HttpWebResponse)request.GetResponse();
            streamReader   = new StreamReader(response.GetResponseStream());
            responseString = streamReader.ReadToEnd();
            response.Close();
        }
Пример #3
0
        /// <summary>
        /// Control the thermostat
        /// </summary>
        /// <param name="systemSwitch">Off, Heat, Cool</param>
        /// <param name="setPoint">Set poitn for heating or cooling</param>
        /// <param name="holdHour">Hours to hold for. E.g. 2 holds for 2 hours.</param>
        /// <param name="holdMinute">Minutes to hold for in multiples of 15 minutes. E.g. 2 = 30 minutes</param>
        public void SetHoldUntil(SystemSwitchEnum systemSwitch, int setPoint, int holdHour, int holdMinute)
        {
            int nextPeriod = (DateTime.Now.Hour + holdHour) * 4 + (int)Math.Ceiling(DateTime.Now.Minute / 15.0) + holdMinute;

            Set(systemSwitch, ScheduleEnum.HoldUntil, setPoint, nextPeriod);
        }