public void ParseFrom(byte[] buffer, int offset, int size) { if (buffer == null) { return; } ProtoBufferReader reader = new ProtoBufferReader(buffer, offset, size); foreach (ProtoBufferObject obj in reader.ProtoBufferObjs) { switch (obj.FieldNumber) { case 1: DurationList.Add(obj.Value); break; case 2: Num0List.Add(obj.Value); break; default: break; } } }
public bool InitDevice() { SettingView = false; AuthProcessView = false; ThermostatAPI api = Global.Instance.ThermostatAPI; Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; string token = localSettings.Values["NestAccessToken"] as string; if (string.IsNullOrEmpty(token)) { Setting(); return(false); } else { api.ApplyAccessToken(token); Task <bool> t = Task.Run(async() => await api.GetDevices()); t.Wait(); if (t.Result) { int count = DeviceList.Count; if (0 == count) { foreach (ThermostatDevice d in api.ThermostatDevices) { FanDuration nfd = DurationList.Where(L => L.Duration == d.fan_timer_duration.ToString()).SingleOrDefault(); Models.Thermostat nts = new Models.Thermostat(d); nts.Duration = nfd; nts.RollDuration = nfd; nts.Tick = 1; //("C" == nts.temperature_scale) ? 1 : 2; nts.FanRun = nts.fan_timer_active == true; nts.FanStop = nts.fan_timer_active == false; if (d == api.ThermostatDevices.First()) { nts.FanBrush = new SolidColorBrush(Colors.White); nts.FanBallBrush = new SolidColorBrush(Colors.White); nts.Duration.Brush = new SolidColorBrush(Color.FromArgb(0xff, 0xff, 0xcb, 0x00)); nts.Duration.BallBrush = new SolidColorBrush(Color.FromArgb(0xff, 0xff, 0xcb, 0x00)); } DeviceList.Add(nts); } } else { if (api.ThermostatDevices.Count < count) { DeviceList.Clear(); } foreach (ThermostatDevice d in api.ThermostatDevices) { FanDuration nfd = DurationList.Where(L => L.Duration == d.fan_timer_duration.ToString()).SingleOrDefault(); Models.Thermostat tm = DeviceList.Where(T => T.device_id == d.device_id).SingleOrDefault(); if (null == tm || string.IsNullOrEmpty(tm.device_id)) { Models.Thermostat nts = new Models.Thermostat(d); nts.Duration = nfd; nts.RollDuration = nfd; nts.Tick = 1; //("C" == nts.temperature_scale) ? 1 : 2; nts.FanRun = nts.fan_timer_active == true; nts.FanStop = nts.fan_timer_active == false; DeviceList.Add(nts); continue; } if (null != tm || false == string.IsNullOrEmpty(tm.device_id)) { tm.Update(d, nfd); } } } if (firstInit) { firstInit = false; OnTemperatureSetting = true; } return(true); } else { Setting(); } return(false); } }