コード例 #1
0
        private async void SetHvacModeAsync(HvacMode hvacMode)
        {
            var thermostat = GetFirstThermostat();

            if (thermostat.HvacMode == hvacMode)
            {
                return;
            }

            try {
                _statusProvider.Stop();

                thermostat.HvacMode = hvacMode;
                var result = await _nestWebService.SetHvacModeAsync(thermostat, hvacMode);

                if (_exceptionHandler.IsErrorHandled(result.Error, result.Exception))
                {
                    return;
                }

                await _statusUpdater.UpdateStatusAsync();
            }
            finally {
                _statusProvider.Start();
            }
        }
コード例 #2
0
        public async Task <WebServiceResult> SetHvacModeAsync(Thermostat thermostat, HvacMode hvacMode)
        {
            string url            = string.Format(@"{0}/v2/put/shared.{1}", _sessionProvider.TransportUrl, thermostat.ID);
            string hvacModeString = _deserializer.GetHvacModeString(hvacMode);
            string requestString  = string.Format("{{\"target_temperature_type\":\"{0}\"}}", hvacModeString);

            return(await SendPutRequestAsync(url, requestString));
        }
コード例 #3
0
ファイル: NestApi.cs プロジェクト: cato976/DomoTroller2
        public async Task <JObject> AdjustModeAsync(string deviceId, HvacMode mode)
        {
            var url = BASE_URL + "devices/thermostats/{0}?auth={1}";

            var field = "hvac_mode";

            var thermostat = await GetThermostatAsync(deviceId);

            var formattedUrl = string.Format(
                url,
                thermostat.DeviceId,
                AccessToken);

            var formattedField = string.Format(
                field);

            string modeString;

            if (mode == HvacMode.HeatCool)
            {
                modeString = "heat-cool";
            }
            else
            {
                modeString = mode.ToString().ToLower();
            }

            var json = @"{""" + formattedField + @""": """ + modeString + @"""}";

            var r = await http.PutAsync(formattedUrl, new StringContent(
                                            json,
                                            Encoding.UTF8,
                                            "application/json"));

            try
            {
                r.EnsureSuccessStatusCode();
            }
            catch (Exception e)
            {
                Trace.TraceInformation("Exception in AdjustModeAsync: {0}", e.Message);
            }

            var data = await r.Content.ReadAsStringAsync();

            return(JObject.Parse(data));
        }
コード例 #4
0
 private void UpdateHvacModeVisualState(bool isAway, HvacMode hvacMode)
 {
     if (isAway)
     {
         GoToVisualState(VisualStateAway);
     }
     else if (hvacMode == HvacMode.HeatAndCool)
     {
         GoToVisualState(VisualStateTemperatureRange);
     }
     else if (hvacMode == HvacMode.Off)
     {
         GoToVisualState(VisualStateOff);
     }
     else
     {
         GoToVisualState(VisualStateTemperatureTarget);
     }
 }
コード例 #5
0
        private async void SetHvacModeAsync(HvacMode hvacMode)
        {
            var thermostat = GetFirstThermostat();

            if (thermostat.HvacMode == hvacMode)
            {
                return;
            }

            await PauseStatusProviderWhile(async() => {
                thermostat.HvacMode = hvacMode;
                var result          = await _nestWebService.SetHvacModeAsync(thermostat, hvacMode);
                if (IsErrorHandled(result.Error, result.Exception))
                {
                    return;
                }

                await _statusUpdater.UpdateStatusAsync();
            });
        }
コード例 #6
0
        private void RefreshFromHvacMode(HvacMode hvacMode)
        {
            bool isHeatEnabled = hvacMode == HvacMode.HeatAndCool || hvacMode == HvacMode.HeatOnly;

            if (isHeatEnabled)
            {
                HeatDotBrush = (Brush)Resources["HeatDotBrush"];
            }
            else
            {
                HeatDotBrush = (Brush)Resources["DisabledDotBrush"];
            }

            bool isCoolEnabled = hvacMode == HvacMode.HeatAndCool || hvacMode == HvacMode.CoolOnly;

            if (isCoolEnabled)
            {
                CoolDotBrush = (Brush)Resources["CoolDotBrush"];
            }
            else
            {
                CoolDotBrush = (Brush)Resources["DisabledDotBrush"];
            }

            if (hvacMode == HvacMode.Off)
            {
                Label = "OFF";
            }
            if (hvacMode == HvacMode.HeatOnly)
            {
                Label = "HEAT ONLY";
            }
            if (hvacMode == HvacMode.CoolOnly)
            {
                Label = "COOL ONLY";
            }
            if (hvacMode == HvacMode.HeatAndCool)
            {
                Label = "HEAT + COOL";
            }
        }
コード例 #7
0
        public string GetHvacModeString(HvacMode hvacMode)
        {
            if (hvacMode == HvacMode.HeatAndCool)
            {
                return("range");
            }
            if (hvacMode == HvacMode.HeatOnly)
            {
                return("heat");
            }
            if (hvacMode == HvacMode.CoolOnly)
            {
                return("cool");
            }
            if (hvacMode == HvacMode.Off)
            {
                return("off");
            }

            throw new InvalidOperationException();
        }
コード例 #8
0
        private void RefreshFromHvacMode(HvacMode hvacMode)
        {
            bool isHeatEnabled = hvacMode == HvacMode.HeatAndCool || hvacMode == HvacMode.HeatOnly;
            if (isHeatEnabled)
                HeatDotBrush = (Brush) Resources["HeatDotBrush"];
            else
                HeatDotBrush = (Brush) Resources["DisabledDotBrush"];

            bool isCoolEnabled = hvacMode == HvacMode.HeatAndCool || hvacMode == HvacMode.CoolOnly;
            if (isCoolEnabled)
                CoolDotBrush = (Brush) Resources["CoolDotBrush"];
            else
                CoolDotBrush = (Brush) Resources["DisabledDotBrush"];

            if (hvacMode == HvacMode.Off)
                Label = "OFF";
            if (hvacMode == HvacMode.HeatOnly)
                Label = "HEAT ONLY";
            if (hvacMode == HvacMode.CoolOnly)
                Label = "COOL ONLY";
            if (hvacMode == HvacMode.HeatAndCool)
                Label = "HEAT + COOL";
        }
コード例 #9
0
ファイル: MainPage.xaml.cs プロジェクト: garyjohnson/wpnest
		private void SelectHvacControl(HvacMode hvacMode) {
			hvacPicker.SelectedItem = hvacPicker.Items.Cast<HvacModeControl>().First(h => h.HvacMode == hvacMode);
		}
コード例 #10
0
 private void SelectHvacControl(HvacMode hvacMode)
 {
     hvacPicker.SelectedItem = hvacPicker.Items.Cast <HvacModeControl>().First(h => h.HvacMode == hvacMode);
 }
コード例 #11
0
ファイル: NestWebService.cs プロジェクト: garyjohnson/wpnest
		public async Task<WebServiceResult> SetHvacModeAsync(Thermostat thermostat, HvacMode hvacMode) {
			string url = string.Format(@"{0}/v2/put/shared.{1}", _sessionProvider.TransportUrl, thermostat.ID);
			string hvacModeString = _deserializer.GetHvacModeString(hvacMode);
			string requestString = string.Format("{{\"target_temperature_type\":\"{0}\"}}", hvacModeString);
			return await SendPutRequestAsync(url, requestString);
		}
コード例 #12
0
		public string GetHvacModeString(HvacMode hvacMode) {
			if (hvacMode == HvacMode.HeatAndCool)
				return "range";
			if (hvacMode == HvacMode.HeatOnly)
				return "heat";
			if(hvacMode == HvacMode.CoolOnly)
				return "cool";
			if(hvacMode == HvacMode.Off)
				return "off";

			throw new InvalidOperationException();
		}
コード例 #13
0
ファイル: NestViewModel.cs プロジェクト: garyjohnson/wpnest
		private async void SetHvacModeAsync(HvacMode hvacMode) {
			var thermostat = GetFirstThermostat();
			if (thermostat.HvacMode == hvacMode)
				return;

			await PauseStatusProviderWhile(async () => {
				thermostat.HvacMode = hvacMode;
				var result = await _nestWebService.SetHvacModeAsync(thermostat, hvacMode);
				if (IsErrorHandled(result.Error, result.Exception))
					return;

				await _statusUpdater.UpdateStatusAsync();
			});
		}
コード例 #14
0
		private void UpdateHvacModeVisualState(bool isAway, HvacMode hvacMode) {
			if (isAway)
				GoToVisualState(VisualStateAway);
			else if (hvacMode == HvacMode.HeatAndCool)
				GoToVisualState(VisualStateTemperatureRange);
			else if (hvacMode == HvacMode.Off)
				GoToVisualState(VisualStateOff);
			else
				GoToVisualState(VisualStateTemperatureTarget);
		}