public static async Task ScanDevices(LifxClient lc) { if (scanning) { return; } scanning = true; var db = GetDb(); // Get dream devices var ld = new LifxDiscovery(lc); var nanoTask = NanoDiscovery.Discover(); var hueTask = HueDiscovery.Discover(); var dreamTask = DreamDiscovery.Discover(); var wLedTask = WledDiscovery.Discover(); var bulbTask = ld.Discover(5); await Task.WhenAll(nanoTask, hueTask, dreamTask, bulbTask).ConfigureAwait(false); var leaves = await nanoTask.ConfigureAwait(false); var bridges = await hueTask.ConfigureAwait(false); var dreamDevices = await dreamTask.ConfigureAwait(false); var bulbs = await bulbTask.ConfigureAwait(false); var wleds = await wLedTask.ConfigureAwait(false); var bridgeCol = db.GetCollection <BridgeData>("Dev_Hue"); var nanoCol = db.GetCollection <NanoData>("Dev_Nanoleaf"); var devCol = db.GetCollection <BaseDevice>("Dev_DreamScreen"); var lifxCol = db.GetCollection <LifxData>("Dev_Lifx"); var wledCol = db.GetCollection <WLedData>("Dev_Wled"); foreach (var b in bridges) { bridgeCol.Upsert(b); } foreach (var n in leaves) { nanoCol.Upsert(n); } foreach (var dd in dreamDevices) { devCol.Upsert(dd); } foreach (var b in bulbs) { lifxCol.Upsert(b); } foreach (var w in wleds) { wledCol.Upsert(w); } bridgeCol.EnsureIndex(x => x.Id); nanoCol.EnsureIndex(x => x.Id); devCol.EnsureIndex(x => x.Id); lifxCol.EnsureIndex(x => x.Id); wledCol.EnsureIndex(x => x.Id); scanning = false; }
public IActionResult GetJson() { LogUtil.Write(@"GetJson Called."); var bridgeArray = DataUtil.GetCollection <BridgeData>("Dev_Hue"); if (bridgeArray.Count == 0) { var newBridges = HueDiscovery.Discover().Result; foreach (var b in newBridges) { DataUtil.InsertCollection <BridgeData>("Dev_Hue", b); } } if (DataUtil.GetItem("DsIp") == "127.0.0.1") { var newDevices = DreamDiscovery.Discover(); var devices = DataUtil.GetCollection <BaseDevice>("Dev_DreamScreen"); foreach (var d in devices) { DataUtil.InsertCollection <BaseDevice>("Dev_DreamScreen", d); } } return(Content(DataUtil.GetStoreSerialized(), "application/json")); }