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; }
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); }
async void CheckTemperatureCallback(object state) { // do some work not connected with UI DateTime Current = DateTime.Now; ThermostatDevice target = null; double target_temperature = -1; string temperature_scale = ""; await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { // do some work on UI here; if (0 < ViewModel.DeviceList.Count) { for (int i = 0; i < ViewModel.DeviceList.Count; ++i) { if (ViewModel.DeviceList[i].ChangeTemperature) { if (2000 <= (Current - ViewModel.DeviceList[i].LatestdChangeTime).TotalMilliseconds) { ViewModel.DeviceList[i].ChangeTemperature = false; target = ViewModel.DeviceList[i].Reference; target_temperature = ViewModel.DeviceList[i].target_temperature; temperature_scale = ViewModel.DeviceList[i].temperature_scale; break; } } } } }); if (null == target) { return; } ThermostatAPI api = Global.Instance.ThermostatAPI; Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; string token = localSettings.Values["NestAccessToken"] as string; string t = api.SetTemperature(target, target_temperature, temperature_scale).Result; //Task<string> t = Task.Run(async () => await api.SetTemperature(ViewModel.DeviceList[target].Reference, ViewModel.DeviceList[target].target_temperature, ViewModel.DeviceList[target].temperature_scale)); //t.Wait(); if (t.Contains("error")) { await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { var dialog = new MessageDialog(t); dialog.ShowAsync(); if (api.AuthorizationError) { ViewModel.ToSettingButtonClickedCommand.Execute(null); } }); } }