示例#1
0
        public void Update(ThermostatDevice device, FanDuration fduration, bool init = false)
        {
            if (false == init)
            {
                device.Duplicate(Reference);
            }

            Duration     = fduration;
            RollDuration = fduration;

            name                    = Reference.name;
            where_name              = Reference.where_name;
            is_online               = Reference.is_online;
            temperature_scale       = Reference.temperature_scale;
            ambient_temperature     = ("C" == temperature_scale) ? Reference.ambient_temperature_c : Reference.ambient_temperature_f;
            hvac_mode               = Reference.hvac_mode;
            target_temperature      = ("C" == temperature_scale) ? Reference.target_temperature_c : Reference.target_temperature_f;
            target_temperature_high = ("C" == temperature_scale) ? Reference.target_temperature_high_c : Reference.target_temperature_high_f;
            target_temperature_low  = ("C" == temperature_scale) ? Reference.target_temperature_low_c : Reference.target_temperature_low_f;
            has_fan                 = Reference.has_fan;
            fan_timer_active        = Reference.fan_timer_active;
            fan_timer_duration      = Reference.fan_timer_duration;
            is_locked               = Reference.is_locked;
            locked_temp_min         = ("C" == temperature_scale) ? Reference.locked_temp_min_c : Reference.locked_temp_min_f;
            locked_temp_max         = ("C" == temperature_scale) ? Reference.locked_temp_max_c : Reference.locked_temp_max_f;
            set_temperature_min     = 0;
            set_temperature_max     = 0;
            TickSpacing             = 0;
            Tick                    = 1; //("C" == temperature_scale) ? 1 : 2;
            FanRun                  = Reference.fan_timer_active == true;
            FanStop                 = Reference.fan_timer_active == false;

            Changed = false;
            Changed = true;
        }
示例#2
0
        public void Duplicate(ThermostatDevice td)
        {
            td.device_id                   = this.device_id;
            td.name                        = this.name;
            td.where_id                    = this.where_id;
            td.where_name                  = this.where_name;
            td.label                       = this.label;
            td.name_long                   = this.name_long;
            td.structure_id                = this.structure_id;
            td.humidity                    = this.humidity;
            td.locale                      = this.locale;
            td.temperature_scale           = this.temperature_scale;
            td.is_using_emergency_heat     = this.is_using_emergency_heat;
            td.has_fan                     = this.has_fan;
            td.software_version            = this.software_version;
            td.has_leaf                    = this.has_leaf;
            td.can_heat                    = this.can_heat;
            td.can_cool                    = this.can_cool;
            td.target_temperature_c        = this.target_temperature_c;
            td.target_temperature_f        = this.target_temperature_f;
            td.target_temperature_high_c   = this.target_temperature_high_c;
            td.target_temperature_high_f   = this.target_temperature_high_f;
            td.target_temperature_low_c    = this.target_temperature_low_c;
            td.target_temperature_low_f    = this.target_temperature_low_f;
            td.ambient_temperature_c       = this.ambient_temperature_c;
            td.ambient_temperature_f       = this.ambient_temperature_f;
            td.eco_temperature_high_c      = this.eco_temperature_high_c;
            td.eco_temperature_high_f      = this.eco_temperature_high_f;
            td.eco_temperature_low_c       = this.eco_temperature_low_c;
            td.eco_temperature_low_f       = this.eco_temperature_low_f;
            td.is_locked                   = this.is_locked;
            td.locked_temp_min_c           = this.locked_temp_min_c;
            td.locked_temp_min_f           = this.locked_temp_min_f;
            td.locked_temp_max_c           = this.locked_temp_max_c;
            td.locked_temp_max_f           = this.locked_temp_max_f;
            td.sunlight_correction_active  = this.sunlight_correction_active;
            td.sunlight_correction_enabled = this.sunlight_correction_enabled;
            td.fan_timer_active            = this.fan_timer_active;
            td.fan_timer_timeout           = this.fan_timer_timeout;
            td.fan_timer_duration          = this.fan_timer_duration;
            td.previous_hvac_mode          = this.previous_hvac_mode;
            td.hvac_mode                   = this.hvac_mode;
            td.time_to_target              = this.time_to_target;
            td.time_to_target_training     = this.time_to_target_training;
            td.is_online                   = this.is_online;
            td.hvac_state                  = this.hvac_state;

            td.Structure = this.Structure;
            td.Where     = this.Where;
        }
示例#3
0
        public Thermostat(ThermostatDevice device)
        {
            Reference = device;

            Changed = false;

            FanBrush     = new SolidColorBrush(Color.FromArgb(0xff, 0x87, 0x87, 0x87));
            FanBallBrush = new SolidColorBrush(Colors.Transparent);

            DeviceBrush = new SolidColorBrush(Color.FromArgb(0xff, 0x87, 0x87, 0x87));

            DeviceBallBrush     = new SolidColorBrush(Colors.Transparent);
            DevicePrevBallBrush = new SolidColorBrush(Colors.Transparent);
            DeviceNextBallBrush = new SolidColorBrush(Colors.Transparent);
        }
示例#4
0
        // 목표 온도 설정
        // 9 ~ 32 (℉ = ℃ * 1.8000 + 32.00)
        public async Task <string> SetTemperature(ThermostatDevice device, double target, string scale = "C")
        {
            AuthorizationError = false;

            string tsc = ("C" == scale) ? "target_temperature_c" : "target_temperature_f";

            string api = string.Format("https://developer-api.nest.com/devices/thermostats/{0}?auth={1}",
                                       device.device_id, AuthToken);

            string body = "{\"" + tsc + "\": " + target.ToString() + ", \"temperature_scale\": \"" + scale + "\"}";

            using (System.Net.Http.HttpClient client = HttpApiClient())
            {
                try
                {
                    System.Net.Http.HttpResponseMessage response = await client.PutAsync(new Uri(api), new System.Net.Http.StringContent(body));

                    Uri url = response.Headers.Location;
                    response = await client.PutAsync(url, new System.Net.Http.StringContent(body));

                    string responseContent = await response.Content.ReadAsStringAsync();

                    if (responseContent.Contains("error"))
                    {
                        if (responseContent.Contains("authorization code expired") || responseContent.Contains("authorization code not found"))
                        {
                            AuthorizationError = true;
                        }

                        ErrorMessage = Parse.ErrorMessage(responseContent);
                        return(ErrorMessage);
                    }

                    return(responseContent);
                }
                catch (Exception ex)
                {
                    ErrorMessage = ex.Message;
                }

                return(ErrorMessage);
            }
        }
示例#5
0
        public async Task <string> SetFanOff(ThermostatDevice device)
        {
            AuthorizationError = false;

            string api = string.Format("https://developer-api.nest.com/devices/thermostats/{0}?auth={1}",
                                       device.device_id, AuthToken);

            string body = "{\"fan_timer_active\": false}";

            using (System.Net.Http.HttpClient client = HttpApiClient())
            {
                try
                {
                    System.Net.Http.HttpResponseMessage response = await client.PutAsync(new Uri(api), new System.Net.Http.StringContent(body));

                    Uri url = response.Headers.Location;
                    response = await client.PutAsync(url, new System.Net.Http.StringContent(body));

                    string responseContent = await response.Content.ReadAsStringAsync();

                    if (responseContent.Contains("error"))
                    {
                        if (responseContent.Contains("authorization code expired") || responseContent.Contains("authorization code not found"))
                        {
                            AuthorizationError = true;
                        }

                        ErrorMessage = Parse.ErrorMessage(responseContent);
                        return(ErrorMessage);
                    }

                    return(responseContent);
                }
                catch (Exception ex)
                {
                    ErrorMessage = ex.Message;
                }

                return(ErrorMessage);
            }
        }
示例#6
0
        // 현재 온도 표시
        public async Task <string> GetTemperature(ThermostatDevice device, string scale = "C")
        {
            AuthorizationError = false;

            string tsc = ("C" == scale) ? "ambient_temperature_c" : "ambient_temperature_f";

            string api = string.Format("https://developer-api.nest.com/devices/thermostats/{0}/{1}?auth={2}",
                                       device.device_id, tsc, AuthToken);

            using (HttpClient client = ApiClient())
            {
                try
                {
                    HttpResponseMessage response = await client.GetAsync(new Uri(api));

                    string responseContent = await response.Content.ReadAsStringAsync();

                    if (responseContent.Contains("error"))
                    {
                        if (responseContent.Contains("authorization code expired") || responseContent.Contains("authorization code not found"))
                        {
                            AuthorizationError = true;
                        }

                        ErrorMessage = Parse.ErrorMessage(responseContent);
                        return(ErrorMessage);
                    }

                    return(responseContent);
                }
                catch (Exception ex)
                {
                    ErrorMessage = ex.Message;
                }

                return(ErrorMessage);
            }
        }
示例#7
0
        /// <summary>
        /// is_locked, lock min - max, can_cool, can_heat  -- readonly
        /// is_locked true --> hvac_mode can change
        /// hvac_mode --> heat, cool, heat-cool, eco, off
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public bool Parse(string json)
        {
            try
            {
                dynamic dynObj = JsonConvert.DeserializeObject(json);

                if (null == ThermostatDevices)
                {
                    ThermostatDevices = new List <ThermostatDevice>();
                }
                ThermostatDevices.Clear();


                foreach (var thermostat in dynObj.devices.thermostats)
                {
                    ThermostatDevice tsd = new ThermostatDevice();

                    tsd.device_id                   = thermostat.First.device_id;
                    tsd.name                        = thermostat.First.name;
                    tsd.where_id                    = thermostat.First.where_id;
                    tsd.where_name                  = thermostat.First.where_name;
                    tsd.label                       = thermostat.First.label;
                    tsd.name_long                   = thermostat.First.name_long;
                    tsd.structure_id                = thermostat.First.structure_id;
                    tsd.humidity                    = thermostat.First.humidity;
                    tsd.locale                      = thermostat.First.locale;
                    tsd.temperature_scale           = thermostat.First.temperature_scale;
                    tsd.is_using_emergency_heat     = thermostat.First.is_using_emergency_heat;
                    tsd.has_fan                     = thermostat.First.has_fan;
                    tsd.software_version            = thermostat.First.software_version;
                    tsd.has_leaf                    = thermostat.First.has_leaf;
                    tsd.can_heat                    = thermostat.First.can_heat;
                    tsd.can_cool                    = thermostat.First.can_cool;
                    tsd.target_temperature_c        = thermostat.First.target_temperature_c;
                    tsd.target_temperature_f        = thermostat.First.target_temperature_f;
                    tsd.target_temperature_high_c   = thermostat.First.target_temperature_high_c;
                    tsd.target_temperature_high_f   = thermostat.First.target_temperature_high_f;
                    tsd.target_temperature_low_c    = thermostat.First.target_temperature_low_c;
                    tsd.target_temperature_low_f    = thermostat.First.target_temperature_low_f;
                    tsd.ambient_temperature_c       = thermostat.First.ambient_temperature_c;
                    tsd.ambient_temperature_f       = thermostat.First.ambient_temperature_f;
                    tsd.eco_temperature_high_c      = thermostat.First.eco_temperature_high_c;
                    tsd.eco_temperature_high_f      = thermostat.First.eco_temperature_high_f;
                    tsd.eco_temperature_low_c       = thermostat.First.eco_temperature_low_c;
                    tsd.eco_temperature_low_f       = thermostat.First.eco_temperature_low_f;
                    tsd.is_locked                   = thermostat.First.is_locked;
                    tsd.locked_temp_min_c           = thermostat.First.locked_temp_min_c;
                    tsd.locked_temp_min_f           = thermostat.First.locked_temp_min_f;
                    tsd.locked_temp_max_c           = thermostat.First.locked_temp_max_c;
                    tsd.locked_temp_max_f           = thermostat.First.locked_temp_max_f;
                    tsd.sunlight_correction_active  = thermostat.First.sunlight_correction_active;
                    tsd.sunlight_correction_enabled = thermostat.First.sunlight_correction_enabled;
                    tsd.fan_timer_active            = thermostat.First.fan_timer_active;
                    tsd.fan_timer_timeout           = thermostat.First.fan_timer_timeout;
                    tsd.fan_timer_duration          = thermostat.First.fan_timer_duration;
                    tsd.previous_hvac_mode          = thermostat.First.previous_hvac_mode;
                    tsd.hvac_mode                   = thermostat.First.hvac_mode;
                    tsd.time_to_target              = thermostat.First.time_to_target;
                    tsd.time_to_target_training     = thermostat.First.time_to_target_training;
                    tsd.is_online                   = thermostat.First.is_online;
                    tsd.hvac_state                  = thermostat.First.hvac_state;

                    ThermostatDevices.Add(tsd);
                }


                if (null == Structures)
                {
                    Structures = new List <Structure>();
                }
                Structures.Clear();

                foreach (var structure in dynObj.structures)
                {
                    Structure s = new Structure();

                    s.structure_id = structure.First.structure_id;
                    s.name         = structure.First.name;
                    s.away         = structure.First.name;

                    for (int i = 0; i < structure.First.thermostats.Count; ++i)
                    {
                        ThermostatDevice t = ThermostatDevices.Where(T => structure.First.thermostats[i] == T.device_id).SingleOrDefault();
                        if (null != t && structure.First.thermostats[i] == t.device_id)
                        {
                            s.thermostats.Add(t);
                        }
                    }

                    foreach (var where in structure.First.wheres)
                    {
                        Where w = new Where();

                        w.where_id = where.First.where_id;
                        w.name     = where.First.name;

                        s.wheres.Add(w);
                    }

                    Structures.Add(s);
                }


                foreach (ThermostatDevice tsd in ThermostatDevices)
                {
                    Structure s = Structures.Where(S => tsd.structure_id == S.structure_id).SingleOrDefault();
                    if (null != s && tsd.structure_id == s.structure_id)
                    {
                        tsd.Structure = s;

                        Where w = tsd.Structure.wheres.Where(W => tsd.where_id == W.where_id).SingleOrDefault();
                        if (null != w && tsd.where_id == w.where_id)
                        {
                            tsd.Where = w;
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
            }

            return(false);
        }