private async void _refreshTimer_Tick(object sender, EventArgs e) { IHueObject selected = SelectedObject; List <IHueObject> obj = await SelectedBridge.GetAllObjectsAsync(false, true); List <IHueObject> diff = obj.Where(x => !_listCurrentBridgeHueObjects.Any(y => y.Id == x.Id && y.GetType() == x.GetType())).ToList(); foreach (IHueObject ho in diff) { CurrentBridgeHueObjectsList.Remove(x => x.Id == ho.Id && x.GetType() == ho.GetType()); } foreach (IHueObject o in obj) { IHueObject oldo = _listCurrentBridgeHueObjects.FirstOrDefault(x => x.Id == o.Id && x.GetType() == o.GetType()); if (oldo == null) { _listCurrentBridgeHueObjects.Add(o); } else { RefreshHueObject(ref oldo, o); } } if (SelectedObject is null) { return; } if (obj.Any(x => x.Id == selected.Id && x.GetType() == selected.GetType())) { SelectedObject = selected; } }
public async Task RefreshCurrentListHueObject() { if (SelectedBridge == null) { return; } Cursor_Tools.ShowWaitCursor(); SelectedObject = null; if (!SelectedBridge.Virtual) { log.Info($"Getting list of objects from bridge at {SelectedBridge.IpAddress}."); List <IHueObject> hr = await SelectedBridge.GetAllObjectsAsync(false, true); if (hr != null) { List <IHueObject> listobj = hr; ObservableCollection <IHueObject> newlist = new ObservableCollection <IHueObject>(); switch (WinHueSettings.settings.Sort) { case WinHueSortOrder.Default: CurrentBridgeHueObjectsList = new ObservableCollection <IHueObject>(hr); break; case WinHueSortOrder.Ascending: newlist.AddRange(from item in listobj where item is Light orderby item.name select item); newlist.AddRange(from item in listobj where item is Group orderby item.name select item); newlist.AddRange(from item in listobj where item is Schedule orderby item.name select item); newlist.AddRange(from item in listobj where item is Scene orderby item.name select item); newlist.AddRange( from item in listobj where item is Sensor orderby item.name select item); newlist.AddRange(from item in listobj where item is Rule orderby item.name select item); newlist.AddRange(from item in listobj where item is Resourcelink orderby item.name select item); CurrentBridgeHueObjectsList = new ObservableCollection <IHueObject>(newlist); break; case WinHueSortOrder.Descending: newlist.AddRange(from item in listobj where item is Light orderby item.name descending select item); newlist.AddRange(from item in listobj where item is Group orderby item.name descending select item); newlist.AddRange(from item in listobj where item is Schedule orderby item.name descending select item); newlist.AddRange(from item in listobj where item is Scene orderby item.name descending select item); newlist.AddRange(from item in listobj where item is Sensor orderby item.name descending select item); newlist.AddRange(from item in listobj where item is Rule orderby item.name descending select item); newlist.AddRange(from item in listobj where item is Resourcelink orderby item.name descending select item); CurrentBridgeHueObjectsList = new ObservableCollection <IHueObject>(newlist); break; default: goto case WinHueSortOrder.Default; } CreateExpanders(); } else { CurrentBridgeHueObjectsList = new ObservableCollection <IHueObject>(); log.Info("Bridge update required. Please update the bridge to use WinHue with this bridge."); } } else { log.Info("Virtual Bridge detected. Will skip refresh."); } Cursor_Tools.ShowNormalCursor(); }