From e2f53e0d571817d6df4a79fc07a421e631daab26 Mon Sep 17 00:00:00 2001 From: Thomas Fransolet Date: Mon, 4 Jan 2021 19:42:17 +0100 Subject: [PATCH] Add device by provider - Add check if device already in system --- MyCore/Services/Devices/DeviceService.cs | 12 ++++++++++++ .../Devices/SupportedDevices/YeelightService.cs | 1 - .../MyControlPanel/Database/DeviceDatabaseService.cs | 5 +++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/MyCore/Services/Devices/DeviceService.cs b/MyCore/Services/Devices/DeviceService.cs index 96d581f..bbc11a1 100644 --- a/MyCore/Services/Devices/DeviceService.cs +++ b/MyCore/Services/Devices/DeviceService.cs @@ -135,6 +135,10 @@ namespace MyCore.Services.Devices { List createdArloDevices = new List(); + List existingDevices = _DeviceDatabaseService.GetByprovider(provider.Id); + + arloDevices = arloDevices.Where(yd => !existingDevices.Select(ed => ed.ServiceIdentification).ToList().Contains(yd.deviceId)).ToList(); + foreach (var arlo in arloDevices) { DeviceDetailDTO deviceDetailDTO = new DeviceDetailDTO(); @@ -185,6 +189,10 @@ namespace MyCore.Services.Devices { List createdMerossDevices = new List(); + List existingDevices = _DeviceDatabaseService.GetByprovider(provider.Id); + + merossDevices = merossDevices.Where(yd => !existingDevices.Select(ed => ed.ServiceIdentification).ToList().Contains(yd.uuid)).ToList(); + foreach (var meross in merossDevices) { DeviceDetailDTO deviceDetailDTO = new DeviceDetailDTO(); @@ -232,6 +240,10 @@ namespace MyCore.Services.Devices { List createdYeelightDevices = new List(); + List existingDevices = _DeviceDatabaseService.GetByprovider(provider.Id); + + yeelightDevices = yeelightDevices.Where(yd => !existingDevices.Select(ed => ed.ServiceIdentification).ToList().Contains(yd.Id)).ToList(); + foreach (var light in yeelightDevices) { DeviceDetailDTO deviceDetailDTO = new DeviceDetailDTO(); diff --git a/MyCore/Services/Devices/SupportedDevices/YeelightService.cs b/MyCore/Services/Devices/SupportedDevices/YeelightService.cs index 2318522..166eeae 100644 --- a/MyCore/Services/Devices/SupportedDevices/YeelightService.cs +++ b/MyCore/Services/Devices/SupportedDevices/YeelightService.cs @@ -13,7 +13,6 @@ namespace MyCore.Services public async Task> GetDevices() { devices = await DeviceLocator.Discover(); - return devices; } diff --git a/MyCore/Services/MyControlPanel/Database/DeviceDatabaseService.cs b/MyCore/Services/MyControlPanel/Database/DeviceDatabaseService.cs index e24da37..6f5e53c 100644 --- a/MyCore/Services/MyControlPanel/Database/DeviceDatabaseService.cs +++ b/MyCore/Services/MyControlPanel/Database/DeviceDatabaseService.cs @@ -28,6 +28,11 @@ namespace MyCore.Services.MyControlPanel return _Devices.Find(d => d.Id == id).FirstOrDefault(); } + public List GetByprovider(string providerId) + { + return _Devices.Find(d => d.ProviderId == providerId).ToList(); + } + public bool IsExist(string id) { return _Devices.Find(d => d.Id == id).FirstOrDefault() != null ? true : false;