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(); } }
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)); }
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)); }
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); } }
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(); }); }
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"; } }
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(); }
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"; }
private void SelectHvacControl(HvacMode hvacMode) { hvacPicker.SelectedItem = hvacPicker.Items.Cast<HvacModeControl>().First(h => h.HvacMode == hvacMode); }
private void SelectHvacControl(HvacMode hvacMode) { hvacPicker.SelectedItem = hvacPicker.Items.Cast <HvacModeControl>().First(h => h.HvacMode == hvacMode); }
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); }
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(); }
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(); }); }
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); }