Add device by provider - Add check if device already in system

This commit is contained in:
Thomas Fransolet 2021-01-04 19:42:17 +01:00
parent eaaffaeeae
commit e2f53e0d57
3 changed files with 17 additions and 1 deletions

View File

@ -135,6 +135,10 @@ namespace MyCore.Services.Devices
{
List<DeviceDetailDTO> createdArloDevices = new List<DeviceDetailDTO>();
List<Device> 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<DeviceDetailDTO> createdMerossDevices = new List<DeviceDetailDTO>();
List<Device> 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<DeviceDetailDTO> createdYeelightDevices = new List<DeviceDetailDTO>();
List<Device> 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();

View File

@ -13,7 +13,6 @@ namespace MyCore.Services
public async Task<List<YeelightAPI.Device>> GetDevices()
{
devices = await DeviceLocator.Discover();
return devices;
}

View File

@ -28,6 +28,11 @@ namespace MyCore.Services.MyControlPanel
return _Devices.Find<Device>(d => d.Id == id).FirstOrDefault();
}
public List<Device> GetByprovider(string providerId)
{
return _Devices.Find(d => d.ProviderId == providerId).ToList();
}
public bool IsExist(string id)
{
return _Devices.Find<Device>(d => d.Id == id).FirstOrDefault() != null ? true : false;