mirror of
https://bitbucket.org/myhomie/mycorerepository.git
synced 2025-12-06 09:41:19 +00:00
MC Update deviceController support for meross, arlo and yeelight devices
This commit is contained in:
parent
8934a860fc
commit
28903e1a16
@ -41,16 +41,22 @@ namespace MyCore.Controllers.Devices
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get all devices summary
|
/// Get all devices summary
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="userId">Id of user</param>
|
||||||
[ProducesResponseType(typeof(List<DeviceSummaryDTO>), 200)]
|
[ProducesResponseType(typeof(List<DeviceSummaryDTO>), 200)]
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public ObjectResult GetAll()
|
public ObjectResult GetAll(string userId)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<Device> Devices = _DeviceDatabaseService.GetAll();
|
List<Device> Devices = _DeviceDatabaseService.GetAll(userId);
|
||||||
|
|
||||||
List<DeviceSummaryDTO> devicesSummaryDTO = Devices.Select(d => d.ToSummaryDTO()).ToList();
|
List<DeviceSummaryDTO> devicesSummaryDTO = Devices.Select(d => d.ToSummaryDTO()).ToList();
|
||||||
|
|
||||||
|
foreach (var device in devicesSummaryDTO)
|
||||||
|
{
|
||||||
|
device.ProviderName = _ProviderDatabaseService.GetById(userId, device.ProviderId).Name;
|
||||||
|
}
|
||||||
|
|
||||||
return new OkObjectResult(devicesSummaryDTO);
|
return new OkObjectResult(devicesSummaryDTO);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -62,10 +68,11 @@ namespace MyCore.Controllers.Devices
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a specific device info
|
/// Get a specific device info
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="userId">Id of user</param>
|
||||||
/// <param name="deviceId">id of device</param>
|
/// <param name="deviceId">id of device</param>
|
||||||
[ProducesResponseType(typeof(DeviceDetailDTO), 200)]
|
[ProducesResponseType(typeof(DeviceDetailDTO), 200)]
|
||||||
[HttpGet("{deviceId}")]
|
[HttpGet("{deviceId}")]
|
||||||
public ObjectResult GetDetail(string deviceId)
|
public ObjectResult GetDetail(string userId, string deviceId)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -89,11 +96,10 @@ namespace MyCore.Controllers.Devices
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
if (deviceDetailDTO == null)
|
if (deviceDetailDTO == null)
|
||||||
throw new KeyNotFoundException("Device is null");
|
throw new KeyNotFoundException("Device is null");
|
||||||
|
|
||||||
DeviceDetailDTO deviceCreated = DeviceService.CreateOrUpdate(this._DeviceDatabaseService, this._ProviderDatabaseService, this._LocationDatabaseService, deviceDetailDTO, true);
|
DeviceDetailDTO deviceCreated = DeviceService.CreateOrUpdate(this._DeviceDatabaseService, this._ProviderDatabaseService, this._LocationDatabaseService, deviceDetailDTO.UserId, deviceDetailDTO, true);
|
||||||
|
|
||||||
return new OkObjectResult(deviceCreated);
|
return new OkObjectResult(deviceCreated);
|
||||||
|
|
||||||
@ -133,7 +139,7 @@ namespace MyCore.Controllers.Devices
|
|||||||
if (provider == null)
|
if (provider == null)
|
||||||
throw new KeyNotFoundException("Provider id is null");
|
throw new KeyNotFoundException("Provider id is null");
|
||||||
|
|
||||||
List<DeviceDetailDTO> devicesCreated = await DeviceService.CreateFromProvider(this._DeviceDatabaseService, this._ProviderDatabaseService, this._LocationDatabaseService, provider);
|
List<DeviceDetailDTO> devicesCreated = await DeviceService.CreateFromProvider(this._DeviceDatabaseService, this._ProviderDatabaseService, this._LocationDatabaseService, userId, provider);
|
||||||
|
|
||||||
return new OkObjectResult(devicesCreated);
|
return new OkObjectResult(devicesCreated);
|
||||||
}
|
}
|
||||||
@ -162,18 +168,18 @@ namespace MyCore.Controllers.Devices
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Update a device
|
/// Update a device
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="deviceId">Device Id</param>
|
/// <param name="userId">Device Id</param>
|
||||||
/// <param name="deviceDetailDTO">Device to update</param>
|
/// <param name="deviceDetailDTO">Device to update</param>
|
||||||
[ProducesResponseType(typeof(DeviceDetailDTO), 200)]
|
[ProducesResponseType(typeof(DeviceDetailDTO), 200)]
|
||||||
[HttpPut("{deviceId}")]
|
[HttpPut("{deviceId}")]
|
||||||
public ObjectResult Update(string deviceId, [FromBody] DeviceDetailDTO deviceDetailDTO)
|
public ObjectResult Update(string userId, [FromBody] DeviceDetailDTO deviceDetailDTO)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!_DeviceDatabaseService.IsExist(deviceId))
|
if (!_DeviceDatabaseService.IsExist(deviceDetailDTO.Id))
|
||||||
throw new KeyNotFoundException("Device does not exist");
|
throw new KeyNotFoundException("Device does not exist");
|
||||||
|
|
||||||
DeviceDetailDTO deviceUpdated = DeviceService.CreateOrUpdate(this._DeviceDatabaseService, this._ProviderDatabaseService, this._LocationDatabaseService, deviceDetailDTO, false);
|
DeviceDetailDTO deviceUpdated = DeviceService.CreateOrUpdate(this._DeviceDatabaseService, this._ProviderDatabaseService, this._LocationDatabaseService, userId, deviceDetailDTO, false);
|
||||||
|
|
||||||
return new OkObjectResult(deviceUpdated);
|
return new OkObjectResult(deviceUpdated);
|
||||||
}
|
}
|
||||||
@ -206,5 +212,25 @@ namespace MyCore.Controllers.Devices
|
|||||||
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete a device
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userId">Id of user</param>
|
||||||
|
[HttpDelete("user/{userId}")]
|
||||||
|
public ObjectResult DeleteAllForUser(string userId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Check if exist
|
||||||
|
_DeviceDatabaseService.RemoveForUser(userId);
|
||||||
|
|
||||||
|
return new OkObjectResult(201);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -91,11 +91,14 @@ namespace MyCore.Controllers.Devices
|
|||||||
throw new KeyNotFoundException("User not found");
|
throw new KeyNotFoundException("User not found");
|
||||||
|
|
||||||
if (providerDTO == null)
|
if (providerDTO == null)
|
||||||
throw new KeyNotFoundException("Provider is null");
|
throw new KeyNotFoundException("Provider is null");
|
||||||
|
|
||||||
ProviderDTO providerCreated = ProviderService.CreateOrUpdate(this._ProviderDatabaseService, userId, providerDTO, true);
|
if (_ProviderDatabaseService.AlreadyExistForUser(userId, providerDTO.Name))
|
||||||
|
throw new ArgumentException("Provider already exists");
|
||||||
|
|
||||||
return new OkObjectResult(providerCreated);
|
ProviderDTO providerCreated = ProviderService.CreateOrUpdate(this._ProviderDatabaseService, userId, providerDTO, true);
|
||||||
|
|
||||||
|
return new OkObjectResult(providerCreated);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (InvalidOperationException ex)
|
catch (InvalidOperationException ex)
|
||||||
@ -106,6 +109,10 @@ namespace MyCore.Controllers.Devices
|
|||||||
{
|
{
|
||||||
return new BadRequestObjectResult(ex.Message) { StatusCode = 404 };
|
return new BadRequestObjectResult(ex.Message) { StatusCode = 404 };
|
||||||
}
|
}
|
||||||
|
catch (ArgumentException ex)
|
||||||
|
{
|
||||||
|
return new BadRequestObjectResult(ex.Message) { StatusCode = 409 };
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||||
|
|||||||
20
MyCore/DTO/Common/DeviceType.cs
Normal file
20
MyCore/DTO/Common/DeviceType.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace MyCore.DTO.Common
|
||||||
|
{
|
||||||
|
public enum DeviceType // TO BE Continued
|
||||||
|
{
|
||||||
|
Sensor = 1,
|
||||||
|
Actuator,
|
||||||
|
Camera,
|
||||||
|
Light,
|
||||||
|
Sound,
|
||||||
|
Plug,
|
||||||
|
Thermostat,
|
||||||
|
Valve,
|
||||||
|
Gateway
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -11,16 +11,24 @@ namespace MyCore.DTO.MyControlPanel
|
|||||||
{
|
{
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
|
|
||||||
|
public string UserId { get; set; }
|
||||||
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
public string Model { get; set; }
|
public string Model { get; set; }
|
||||||
|
|
||||||
|
public DeviceType Type { get; set; }
|
||||||
|
|
||||||
public bool Status { get; set; }
|
public bool Status { get; set; }
|
||||||
|
|
||||||
public ConnectionStatus ConnectionStatus { get; set; }
|
public ConnectionStatus ConnectionStatus { get; set; }
|
||||||
|
|
||||||
public string LocationId { get; set; }
|
public string LocationId { get; set; }
|
||||||
|
|
||||||
|
public string ProviderId { get; set; }
|
||||||
|
|
||||||
|
public string ProviderName { get; set; }
|
||||||
|
|
||||||
public LocationDTO Location { get; set; }
|
public LocationDTO Location { get; set; }
|
||||||
|
|
||||||
public DateTime LastStateDate { get; set; }
|
public DateTime LastStateDate { get; set; }
|
||||||
@ -34,10 +42,14 @@ namespace MyCore.DTO.MyControlPanel
|
|||||||
{
|
{
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
|
|
||||||
|
public string UserId { get; set; }
|
||||||
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
public string Model { get; set; }
|
public string Model { get; set; }
|
||||||
|
|
||||||
|
public DeviceType Type { get; set; }
|
||||||
|
|
||||||
public string FirmwareVersion { get; set; }
|
public string FirmwareVersion { get; set; }
|
||||||
|
|
||||||
public int Port { get; set; }
|
public int Port { get; set; }
|
||||||
@ -70,7 +82,9 @@ namespace MyCore.DTO.MyControlPanel
|
|||||||
|
|
||||||
public string ProviderId { get; set; }
|
public string ProviderId { get; set; }
|
||||||
|
|
||||||
public List<string> Groups { get; set; }
|
public string ProviderName { get; set; }
|
||||||
|
|
||||||
|
public List<string> GroupIds { get; set; }
|
||||||
|
|
||||||
public Dictionary<string, object> Properties { get; set; }
|
public Dictionary<string, object> Properties { get; set; }
|
||||||
|
|
||||||
|
|||||||
@ -19,6 +19,10 @@ namespace MyCore.Models.MyControlPanel.Database
|
|||||||
[BsonRepresentation(BsonType.ObjectId)]
|
[BsonRepresentation(BsonType.ObjectId)]
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("UserId")]
|
||||||
|
[BsonRequired]
|
||||||
|
public string UserId { get; set; }
|
||||||
|
|
||||||
[BsonElement("Name")]
|
[BsonElement("Name")]
|
||||||
[BsonRequired]
|
[BsonRequired]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
@ -38,6 +42,9 @@ namespace MyCore.Models.MyControlPanel.Database
|
|||||||
[BsonElement("Status")]
|
[BsonElement("Status")]
|
||||||
public bool Status { get; set; }
|
public bool Status { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Type")]
|
||||||
|
public DeviceType Type { get; set; }
|
||||||
|
|
||||||
[BsonElement("ConnectionStatus")]
|
[BsonElement("ConnectionStatus")]
|
||||||
public ConnectionStatus ConnectionStatus { get; set; }
|
public ConnectionStatus ConnectionStatus { get; set; }
|
||||||
|
|
||||||
@ -89,10 +96,13 @@ namespace MyCore.Models.MyControlPanel.Database
|
|||||||
return new DeviceSummaryDTO()
|
return new DeviceSummaryDTO()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
|
UserId = UserId,
|
||||||
Name = Name,
|
Name = Name,
|
||||||
Model = Model,
|
Model = Model,
|
||||||
|
Type = Type,
|
||||||
Status = Status,
|
Status = Status,
|
||||||
ConnectionStatus = ConnectionStatus,
|
ConnectionStatus = ConnectionStatus,
|
||||||
|
ProviderId = ProviderId,
|
||||||
LocationId = LocationId, // Check if correct way
|
LocationId = LocationId, // Check if correct way
|
||||||
// Location =
|
// Location =
|
||||||
LastStateDate = LastStateDate,
|
LastStateDate = LastStateDate,
|
||||||
@ -106,8 +116,10 @@ namespace MyCore.Models.MyControlPanel.Database
|
|||||||
return new DeviceDetailDTO()
|
return new DeviceDetailDTO()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
|
UserId = UserId,
|
||||||
Name = Name,
|
Name = Name,
|
||||||
Model = Model,
|
Model = Model,
|
||||||
|
Type = Type,
|
||||||
Status = Status,
|
Status = Status,
|
||||||
Port = Port,
|
Port = Port,
|
||||||
FirmwareVersion = FirmwareVersion,
|
FirmwareVersion = FirmwareVersion,
|
||||||
@ -122,7 +134,7 @@ namespace MyCore.Models.MyControlPanel.Database
|
|||||||
IpAddress = IpAddress,
|
IpAddress = IpAddress,
|
||||||
ServiceIdentification = ServiceIdentification,
|
ServiceIdentification = ServiceIdentification,
|
||||||
ProviderId = ProviderId,
|
ProviderId = ProviderId,
|
||||||
Groups = GroupIds,
|
GroupIds = GroupIds,
|
||||||
Properties = Properties,
|
Properties = Properties,
|
||||||
SupportedOperations = SupportedOperations,
|
SupportedOperations = SupportedOperations,
|
||||||
Battery = Battery,
|
Battery = Battery,
|
||||||
|
|||||||
@ -45,6 +45,10 @@ namespace MyCore.Models.MyControlPanel.Database
|
|||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
Name = Name,
|
Name = Name,
|
||||||
|
UserId = UserId,
|
||||||
|
/*Username = Username,
|
||||||
|
Password = Password,
|
||||||
|
ApiKey = ApiKey,*/
|
||||||
Active = Active
|
Active = Active
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,7 @@ namespace MyCore.Services.Devices
|
|||||||
public class DeviceService
|
public class DeviceService
|
||||||
{
|
{
|
||||||
|
|
||||||
public static DeviceDetailDTO CreateOrUpdate(DeviceDatabaseService _DeviceDatabaseService, ProviderDatabaseService _ProviderDatabaseService, LocationDatabaseService _LocationDatabaseService, DeviceDetailDTO deviceDetailDTO, bool create)
|
public static DeviceDetailDTO CreateOrUpdate(DeviceDatabaseService _DeviceDatabaseService, ProviderDatabaseService _ProviderDatabaseService, LocationDatabaseService _LocationDatabaseService, string userId, DeviceDetailDTO deviceDetailDTO, bool create)
|
||||||
{
|
{
|
||||||
Device device;
|
Device device;
|
||||||
if (create)
|
if (create)
|
||||||
@ -26,12 +26,14 @@ namespace MyCore.Services.Devices
|
|||||||
device = _DeviceDatabaseService.GetById(deviceDetailDTO.Id);
|
device = _DeviceDatabaseService.GetById(deviceDetailDTO.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_DeviceDatabaseService.IsAlreadyHere(deviceDetailDTO.IpAddress, deviceDetailDTO.Port) && create)
|
if (_DeviceDatabaseService.IsAlreadyHere(userId, deviceDetailDTO.ServiceIdentification, deviceDetailDTO.Model) && create)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
device.Name = deviceDetailDTO.Name;
|
device.UserId = userId;
|
||||||
|
device.Name = deviceDetailDTO.Name;
|
||||||
|
|
||||||
if (_ProviderDatabaseService.IsExist(deviceDetailDTO.ProviderId))
|
if (_ProviderDatabaseService.IsExist(deviceDetailDTO.ProviderId))
|
||||||
device.ProviderId = deviceDetailDTO.ProviderId;
|
device.ProviderId = deviceDetailDTO.ProviderId;
|
||||||
else
|
else
|
||||||
@ -44,14 +46,15 @@ namespace MyCore.Services.Devices
|
|||||||
|
|
||||||
device.Port = deviceDetailDTO.Port;
|
device.Port = deviceDetailDTO.Port;
|
||||||
device.Model = deviceDetailDTO.Model;
|
device.Model = deviceDetailDTO.Model;
|
||||||
|
device.Type = deviceDetailDTO.Type;
|
||||||
device.FirmwareVersion = deviceDetailDTO.FirmwareVersion;
|
device.FirmwareVersion = deviceDetailDTO.FirmwareVersion;
|
||||||
device.Status = deviceDetailDTO.Status;
|
device.Status = deviceDetailDTO.Status;
|
||||||
if (create)
|
if (create)
|
||||||
device.ConnectionStatus = ConnectionStatus.Unknown;
|
device.ConnectionStatus = ConnectionStatus.Unknown;
|
||||||
else
|
else
|
||||||
device.ConnectionStatus = deviceDetailDTO.ConnectionStatus;
|
device.ConnectionStatus = deviceDetailDTO.ConnectionStatus;
|
||||||
device.Status = device.Status;
|
device.Status = deviceDetailDTO.Status;
|
||||||
device.LocationId = device.LocationId;
|
device.LocationId = deviceDetailDTO.LocationId;
|
||||||
device.CreatedDate = DateTime.Now;
|
device.CreatedDate = DateTime.Now;
|
||||||
device.UpdatedDate = DateTime.Now;
|
device.UpdatedDate = DateTime.Now;
|
||||||
|
|
||||||
@ -60,11 +63,11 @@ namespace MyCore.Services.Devices
|
|||||||
device.ServiceIdentification = deviceDetailDTO.ServiceIdentification;
|
device.ServiceIdentification = deviceDetailDTO.ServiceIdentification;
|
||||||
device.Battery = deviceDetailDTO.Battery;
|
device.Battery = deviceDetailDTO.Battery;
|
||||||
device.BatteryStatus = deviceDetailDTO.BatteryStatus;
|
device.BatteryStatus = deviceDetailDTO.BatteryStatus;
|
||||||
device.GroupIds = device.GroupIds;
|
device.GroupIds = deviceDetailDTO.GroupIds;
|
||||||
// Todo structure Properties
|
// Todo structure Properties
|
||||||
device.Properties = device.Properties;
|
device.Properties = deviceDetailDTO.Properties;
|
||||||
// Todo structure SupportedOperations
|
// Todo structure SupportedOperations
|
||||||
device.SupportedOperations = device.SupportedOperations;
|
device.SupportedOperations = deviceDetailDTO.SupportedOperations;
|
||||||
|
|
||||||
if (create)
|
if (create)
|
||||||
return _DeviceDatabaseService.Create(device).ToDTO();
|
return _DeviceDatabaseService.Create(device).ToDTO();
|
||||||
@ -72,7 +75,7 @@ namespace MyCore.Services.Devices
|
|||||||
return _DeviceDatabaseService.Update(device.Id, device).ToDTO();
|
return _DeviceDatabaseService.Update(device.Id, device).ToDTO();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async static Task<List<DeviceDetailDTO>> CreateFromProvider(DeviceDatabaseService _DeviceDatabaseService, ProviderDatabaseService _ProviderDatabaseService, LocationDatabaseService _LocationDatabaseService, Provider provider)
|
public async static Task<List<DeviceDetailDTO>> CreateFromProvider(DeviceDatabaseService _DeviceDatabaseService, ProviderDatabaseService _ProviderDatabaseService, LocationDatabaseService _LocationDatabaseService, string userId, Provider provider)
|
||||||
{
|
{
|
||||||
if (!ProviderService.IsProviderSupported(provider.Name))
|
if (!ProviderService.IsProviderSupported(provider.Name))
|
||||||
throw new KeyNotFoundException("Provider is not yet supported");
|
throw new KeyNotFoundException("Provider is not yet supported");
|
||||||
@ -84,15 +87,15 @@ namespace MyCore.Services.Devices
|
|||||||
{
|
{
|
||||||
case "Arlo":
|
case "Arlo":
|
||||||
List<Models.Arlo.ArloDevice> arloDevices = new ArloService(provider.Username, provider.Password).GetAllDevices();
|
List<Models.Arlo.ArloDevice> arloDevices = new ArloService(provider.Username, provider.Password).GetAllDevices();
|
||||||
createdDevice = CreateArloDevices(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, arloDevices, provider);
|
createdDevice = CreateArloDevices(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, userId, arloDevices, provider);
|
||||||
break;
|
break;
|
||||||
case "Meross":
|
case "Meross":
|
||||||
List<Models.Meross.MerossDevice> merossDevices = new MerossService(provider.Username, provider.Password).GetMerossDevices();
|
List<Models.Meross.MerossDevice> merossDevices = new MerossService(provider.Username, provider.Password).GetMerossDevices();
|
||||||
createdDevice = CreateMerossDevices(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, merossDevices, provider);
|
createdDevice = CreateMerossDevices(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, userId, merossDevices, provider);
|
||||||
break;
|
break;
|
||||||
case "Yeelight":
|
case "Yeelight":
|
||||||
List<YeelightAPI.Device> yeelightDevices = await new YeelightService().GetDevices();
|
List<YeelightAPI.Device> yeelightDevices = await new YeelightService().GetDevices();
|
||||||
createdDevice = CreateYeelightDevices(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, yeelightDevices, provider);
|
createdDevice = CreateYeelightDevices(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, userId, yeelightDevices, provider);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,7 +111,7 @@ namespace MyCore.Services.Devices
|
|||||||
return createdDevice;
|
return createdDevice;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<DeviceDetailDTO> CreateArloDevices(DeviceDatabaseService _DeviceDatabaseService, ProviderDatabaseService _ProviderDatabaseService, LocationDatabaseService _LocationDatabaseService, List<Models.Arlo.ArloDevice> arloDevices, Provider provider)
|
public static List<DeviceDetailDTO> CreateArloDevices(DeviceDatabaseService _DeviceDatabaseService, ProviderDatabaseService _ProviderDatabaseService, LocationDatabaseService _LocationDatabaseService, string userId, List<Models.Arlo.ArloDevice> arloDevices, Provider provider)
|
||||||
{
|
{
|
||||||
List<DeviceDetailDTO> createdArloDevices = new List<DeviceDetailDTO>();
|
List<DeviceDetailDTO> createdArloDevices = new List<DeviceDetailDTO>();
|
||||||
|
|
||||||
@ -116,41 +119,49 @@ namespace MyCore.Services.Devices
|
|||||||
{
|
{
|
||||||
DeviceDetailDTO deviceDetailDTO = new DeviceDetailDTO();
|
DeviceDetailDTO deviceDetailDTO = new DeviceDetailDTO();
|
||||||
deviceDetailDTO.Name = arlo.deviceName;
|
deviceDetailDTO.Name = arlo.deviceName;
|
||||||
deviceDetailDTO.IpAddress = arlo.deviceId; // TO CHECK
|
|
||||||
deviceDetailDTO.ServiceIdentification = arlo.deviceId;
|
deviceDetailDTO.ServiceIdentification = arlo.deviceId;
|
||||||
deviceDetailDTO.ProviderId = provider.Id;
|
deviceDetailDTO.ProviderId = provider.Id;
|
||||||
deviceDetailDTO.ConnectionStatus = arlo.connectivity.connected ? ConnectionStatus.Connected : ConnectionStatus.Unknown;
|
if (arlo.connectivity != null)
|
||||||
deviceDetailDTO.Status = arlo.connectivity.connected ? true : false; // TODO STATE
|
|
||||||
deviceDetailDTO.Model = arlo.deviceType;
|
|
||||||
//deviceDetailDTO.Port = arlo.; // TO CHECK
|
|
||||||
deviceDetailDTO.FirmwareVersion = arlo.interfaceVersion; // TODO
|
|
||||||
/*Dictionary<string, object> properties = new Dictionary<string, object>();
|
|
||||||
foreach (var property in arlo.properties)
|
|
||||||
{
|
{
|
||||||
properties.Add(property.Key, property.Value);
|
deviceDetailDTO.ConnectionStatus = arlo.connectivity.connected ? ConnectionStatus.Connected : ConnectionStatus.Unknown;
|
||||||
}*/ // TODO
|
deviceDetailDTO.Status = arlo.connectivity.connected ? true : false; // TODO STATE
|
||||||
// deviceDetailDTO.Properties = properties;
|
}
|
||||||
|
else
|
||||||
|
deviceDetailDTO.ConnectionStatus = ConnectionStatus.Unknown;
|
||||||
|
|
||||||
// TODO !
|
deviceDetailDTO.Model = arlo.modelId;
|
||||||
List<string> supportedOperationsDTO = new List<string>();
|
deviceDetailDTO.FirmwareVersion = arlo.interfaceVersion; // TODO
|
||||||
supportedOperationsDTO.Add(arlo.lastImageUploaded.GetType().Name + " : " + arlo.lastImageUploaded);
|
switch (arlo.deviceType)
|
||||||
supportedOperationsDTO.Add(arlo.presignedLastImageUrl.GetType().Name + " : " + arlo.presignedLastImageUrl);
|
{
|
||||||
supportedOperationsDTO.Add(arlo.presignedFullFrameSnapshotUrl.GetType().Name + " : " + arlo.presignedFullFrameSnapshotUrl);
|
case "camera":
|
||||||
supportedOperationsDTO.Add(arlo.presignedSnapshotUrl.GetType().Name + " : " + arlo.presignedSnapshotUrl);
|
deviceDetailDTO.Type = DeviceType.Camera;
|
||||||
deviceDetailDTO.SupportedOperations = supportedOperationsDTO;
|
Dictionary<string, object> properties = new Dictionary<string, object>();
|
||||||
|
properties.Add("lastImageUploaded", arlo.lastImageUploaded);
|
||||||
|
properties.Add("presignedLastImageUrl", arlo.presignedLastImageUrl);
|
||||||
|
properties.Add("presignedFullFrameSnapshotUrl", arlo.presignedFullFrameSnapshotUrl);
|
||||||
|
properties.Add("presignedSnapshotUrl", arlo.presignedSnapshotUrl);
|
||||||
|
deviceDetailDTO.Properties = properties;
|
||||||
|
break;
|
||||||
|
case "siren":
|
||||||
|
deviceDetailDTO.Type = DeviceType.Sound;
|
||||||
|
break;
|
||||||
|
case "basestation":
|
||||||
|
deviceDetailDTO.Type = DeviceType.Gateway;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
deviceDetailDTO.MeansOfCommunications = new List<MeansOfCommunication>();
|
deviceDetailDTO.MeansOfCommunications = new List<MeansOfCommunication>();
|
||||||
deviceDetailDTO.MeansOfCommunications.Add(MeansOfCommunication.Wifi); // TO CHECK
|
deviceDetailDTO.MeansOfCommunications.Add(MeansOfCommunication.Wifi); // To check
|
||||||
|
|
||||||
deviceDetailDTO.CreatedDate = DateTime.Now;
|
deviceDetailDTO.CreatedDate = DateTime.Now;
|
||||||
deviceDetailDTO.UpdatedDate = DateTime.Now;
|
deviceDetailDTO.UpdatedDate = DateTime.Now;
|
||||||
createdArloDevices.Add(CreateOrUpdate(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, deviceDetailDTO, true));
|
createdArloDevices.Add(CreateOrUpdate(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, userId, deviceDetailDTO, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
return createdArloDevices;
|
return createdArloDevices;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<DeviceDetailDTO> CreateMerossDevices(DeviceDatabaseService _DeviceDatabaseService, ProviderDatabaseService _ProviderDatabaseService, LocationDatabaseService _LocationDatabaseService, List<Models.Meross.MerossDevice> merossDevices, Provider provider)
|
public static List<DeviceDetailDTO> CreateMerossDevices(DeviceDatabaseService _DeviceDatabaseService, ProviderDatabaseService _ProviderDatabaseService, LocationDatabaseService _LocationDatabaseService, string userId, List<Models.Meross.MerossDevice> merossDevices, Provider provider)
|
||||||
{
|
{
|
||||||
List<DeviceDetailDTO> createdMerossDevices = new List<DeviceDetailDTO>();
|
List<DeviceDetailDTO> createdMerossDevices = new List<DeviceDetailDTO>();
|
||||||
|
|
||||||
@ -158,12 +169,26 @@ namespace MyCore.Services.Devices
|
|||||||
{
|
{
|
||||||
DeviceDetailDTO deviceDetailDTO = new DeviceDetailDTO();
|
DeviceDetailDTO deviceDetailDTO = new DeviceDetailDTO();
|
||||||
deviceDetailDTO.Name = meross.devName;
|
deviceDetailDTO.Name = meross.devName;
|
||||||
deviceDetailDTO.IpAddress = meross.uuid; // TO CHECK
|
|
||||||
deviceDetailDTO.ServiceIdentification = meross.uuid;
|
deviceDetailDTO.ServiceIdentification = meross.uuid;
|
||||||
deviceDetailDTO.ProviderId = provider.Id;
|
deviceDetailDTO.ProviderId = provider.Id;
|
||||||
deviceDetailDTO.ConnectionStatus = meross.onlineStatus == 1 ? ConnectionStatus.Connected : ConnectionStatus.Disconnected;
|
deviceDetailDTO.ConnectionStatus = meross.onlineStatus == 1 ? ConnectionStatus.Connected : ConnectionStatus.Disconnected;
|
||||||
// deviceDetailDTO.Status = meross. ? true : false; // TODO STATE
|
// deviceDetailDTO.Status = meross. ? true : false; // TODO STATE
|
||||||
deviceDetailDTO.Model = meross.deviceType;
|
deviceDetailDTO.Model = meross.deviceType;
|
||||||
|
switch (deviceDetailDTO.Model) // TODO
|
||||||
|
{
|
||||||
|
case "mss425f":
|
||||||
|
deviceDetailDTO.Type = DeviceType.Plug;
|
||||||
|
break;
|
||||||
|
case "mss310":
|
||||||
|
deviceDetailDTO.Type = DeviceType.Actuator;
|
||||||
|
break;
|
||||||
|
case "msh300":
|
||||||
|
deviceDetailDTO.Type = DeviceType.Gateway;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
deviceDetailDTO.Type = DeviceType.Actuator;
|
||||||
|
break;
|
||||||
|
}
|
||||||
//deviceDetailDTO.Port = arlo.; // TO CHECK
|
//deviceDetailDTO.Port = arlo.; // TO CHECK
|
||||||
deviceDetailDTO.FirmwareVersion = meross.firmwareVersion; // TODO
|
deviceDetailDTO.FirmwareVersion = meross.firmwareVersion; // TODO
|
||||||
/*Dictionary<string, object> properties = new Dictionary<string, object>();
|
/*Dictionary<string, object> properties = new Dictionary<string, object>();
|
||||||
@ -177,7 +202,8 @@ namespace MyCore.Services.Devices
|
|||||||
Dictionary<string, object> properties = new Dictionary<string, object>();
|
Dictionary<string, object> properties = new Dictionary<string, object>();
|
||||||
foreach (var property in meross.channels)
|
foreach (var property in meross.channels)
|
||||||
{
|
{
|
||||||
properties.Add(property.devName, property.type);
|
if (property.type != null)
|
||||||
|
properties.Add(property.devName, property.type);
|
||||||
}
|
}
|
||||||
// deviceDetailDTO.SupportedOperations = supportedOperationsDTO; TODO
|
// deviceDetailDTO.SupportedOperations = supportedOperationsDTO; TODO
|
||||||
|
|
||||||
@ -185,13 +211,13 @@ namespace MyCore.Services.Devices
|
|||||||
deviceDetailDTO.MeansOfCommunications.Add(MeansOfCommunication.Wifi); // TO CHECK
|
deviceDetailDTO.MeansOfCommunications.Add(MeansOfCommunication.Wifi); // TO CHECK
|
||||||
deviceDetailDTO.CreatedDate = DateTime.Now;
|
deviceDetailDTO.CreatedDate = DateTime.Now;
|
||||||
deviceDetailDTO.UpdatedDate = DateTime.Now;
|
deviceDetailDTO.UpdatedDate = DateTime.Now;
|
||||||
createdMerossDevices.Add(CreateOrUpdate(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, deviceDetailDTO, true));
|
createdMerossDevices.Add(CreateOrUpdate(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, userId, deviceDetailDTO, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
return createdMerossDevices;
|
return createdMerossDevices;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<DeviceDetailDTO> CreateYeelightDevices(DeviceDatabaseService _DeviceDatabaseService, ProviderDatabaseService _ProviderDatabaseService, LocationDatabaseService _LocationDatabaseService, List<YeelightAPI.Device> yeelightDevices, Provider provider)
|
public static List<DeviceDetailDTO> CreateYeelightDevices(DeviceDatabaseService _DeviceDatabaseService, ProviderDatabaseService _ProviderDatabaseService, LocationDatabaseService _LocationDatabaseService, string userId, List<YeelightAPI.Device> yeelightDevices, Provider provider)
|
||||||
{
|
{
|
||||||
List<DeviceDetailDTO> createdYeelightDevices = new List<DeviceDetailDTO>();
|
List<DeviceDetailDTO> createdYeelightDevices = new List<DeviceDetailDTO>();
|
||||||
|
|
||||||
@ -200,10 +226,12 @@ namespace MyCore.Services.Devices
|
|||||||
DeviceDetailDTO deviceDetailDTO = new DeviceDetailDTO();
|
DeviceDetailDTO deviceDetailDTO = new DeviceDetailDTO();
|
||||||
deviceDetailDTO.Name = light.Name;
|
deviceDetailDTO.Name = light.Name;
|
||||||
deviceDetailDTO.IpAddress = light.Hostname;
|
deviceDetailDTO.IpAddress = light.Hostname;
|
||||||
|
deviceDetailDTO.ServiceIdentification = light.Id;
|
||||||
deviceDetailDTO.ProviderId = provider.Id;
|
deviceDetailDTO.ProviderId = provider.Id;
|
||||||
deviceDetailDTO.ConnectionStatus = ConnectionStatus.Connected;
|
deviceDetailDTO.ConnectionStatus = ConnectionStatus.Connected;
|
||||||
deviceDetailDTO.Status = false;
|
deviceDetailDTO.Status = false;
|
||||||
deviceDetailDTO.Model = light.Model.ToString();
|
deviceDetailDTO.Model = light.Model.ToString();
|
||||||
|
deviceDetailDTO.Type = DeviceType.Light; // TO CHECK
|
||||||
deviceDetailDTO.Port = light.Port;
|
deviceDetailDTO.Port = light.Port;
|
||||||
deviceDetailDTO.FirmwareVersion = light.FirmwareVersion;
|
deviceDetailDTO.FirmwareVersion = light.FirmwareVersion;
|
||||||
Dictionary<string, object> properties = new Dictionary<string, object>();
|
Dictionary<string, object> properties = new Dictionary<string, object>();
|
||||||
@ -222,7 +250,7 @@ namespace MyCore.Services.Devices
|
|||||||
deviceDetailDTO.MeansOfCommunications.Add(MeansOfCommunication.Wifi);
|
deviceDetailDTO.MeansOfCommunications.Add(MeansOfCommunication.Wifi);
|
||||||
deviceDetailDTO.CreatedDate = DateTime.Now;
|
deviceDetailDTO.CreatedDate = DateTime.Now;
|
||||||
deviceDetailDTO.UpdatedDate = DateTime.Now;
|
deviceDetailDTO.UpdatedDate = DateTime.Now;
|
||||||
createdYeelightDevices.Add(CreateOrUpdate(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, deviceDetailDTO, true));
|
createdYeelightDevices.Add(CreateOrUpdate(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, userId, deviceDetailDTO, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
return createdYeelightDevices;
|
return createdYeelightDevices;
|
||||||
|
|||||||
@ -28,7 +28,7 @@ namespace MyCore.Services
|
|||||||
private string _logUrl = $"{_merossUrl}/v1/log/user";
|
private string _logUrl = $"{_merossUrl}/v1/log/user";
|
||||||
private string _devList = $"{_merossUrl}/v1/Device/devList";
|
private string _devList = $"{_merossUrl}/v1/Device/devList";
|
||||||
|
|
||||||
private string username = "thomas.fransolet@hotmail.be";
|
private static string username = "thomas.fransolet@hotmail.be";
|
||||||
private static string password = "Coconuts07";
|
private static string password = "Coconuts07";
|
||||||
|
|
||||||
private static ResultToken resultToken;
|
private static ResultToken resultToken;
|
||||||
|
|||||||
@ -20,9 +20,9 @@ namespace MyCore.Services.MyControlPanel
|
|||||||
var database = client.GetDatabase("MyCoreDb");
|
var database = client.GetDatabase("MyCoreDb");
|
||||||
_Devices = database.GetCollection<Device>("Devices");
|
_Devices = database.GetCollection<Device>("Devices");
|
||||||
}
|
}
|
||||||
public List<Device> GetAll()
|
public List<Device> GetAll(string userId)
|
||||||
{
|
{
|
||||||
return _Devices.Find(d => true).ToList();
|
return _Devices.Find(d => d.UserId == userId).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Device GetById(string id)
|
public Device GetById(string id)
|
||||||
@ -35,9 +35,9 @@ namespace MyCore.Services.MyControlPanel
|
|||||||
return _Devices.Find<Device>(d => d.Id == id).FirstOrDefault() != null ? true : false;
|
return _Devices.Find<Device>(d => d.Id == id).FirstOrDefault() != null ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsAlreadyHere(string ipAddress, int port)
|
public bool IsAlreadyHere(string userId, string serviceIdentification, string model)
|
||||||
{
|
{
|
||||||
return _Devices.Find<Device>(d => d.IpAddress == ipAddress && d.Port == port).FirstOrDefault() != null ? true : false;
|
return _Devices.Find<Device>(d => d.UserId == userId && d.ServiceIdentification == serviceIdentification && d.Model == model).FirstOrDefault() != null ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Device Create(Device device)
|
public Device Create(Device device)
|
||||||
@ -56,5 +56,10 @@ namespace MyCore.Services.MyControlPanel
|
|||||||
{
|
{
|
||||||
_Devices.DeleteOne(device => device.Id == id);
|
_Devices.DeleteOne(device => device.Id == id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void RemoveForUser(string userId)
|
||||||
|
{
|
||||||
|
_Devices.DeleteMany(device => device.UserId == userId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,6 +29,11 @@ namespace MyCore.Services.MyControlPanel
|
|||||||
return _Providers.Find<Provider>(p => p.Id == id && p.UserId == userId).FirstOrDefault();
|
return _Providers.Find<Provider>(p => p.Id == id && p.UserId == userId).FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool AlreadyExistForUser(string userId, string name)
|
||||||
|
{
|
||||||
|
return _Providers.Find<Provider>(p => p.UserId == userId && p.Name == name).FirstOrDefault() != null ? true : false; ;
|
||||||
|
}
|
||||||
|
|
||||||
public Provider GetByName(string name)
|
public Provider GetByName(string name)
|
||||||
{
|
{
|
||||||
return _Providers.Find<Provider>(p => p.Name == name).FirstOrDefault();
|
return _Providers.Find<Provider>(p => p.Name == name).FirstOrDefault();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user