mirror of
https://bitbucket.org/myhomie/mycorerepository.git
synced 2025-12-06 01:31:19 +00:00
Add actions to alarm detail + add device detail to automation detail
This commit is contained in:
parent
971aa63229
commit
d212510392
@ -26,6 +26,7 @@ namespace MyCore.Interfaces.DTO
|
|||||||
public class AlarmModeDetailDTO : AlarmModeDTO
|
public class AlarmModeDetailDTO : AlarmModeDTO
|
||||||
{
|
{
|
||||||
public List<Trigger> Triggers { get; set; }
|
public List<Trigger> Triggers { get; set; }
|
||||||
|
public List<MyCore.Interfaces.Models.Action> Actions { get; set; }
|
||||||
public List<DeviceDetailDTO> Devices { get; set; }
|
public List<DeviceDetailDTO> Devices { get; set; }
|
||||||
public ProgrammedMode ProgrammedMode { get; set; }
|
public ProgrammedMode ProgrammedMode { get; set; }
|
||||||
public GeolocalizedMode GeolocalizedMode { get; set; }
|
public GeolocalizedMode GeolocalizedMode { get; set; }
|
||||||
|
|||||||
@ -22,5 +22,6 @@ namespace MyCore.Interfaces.DTO
|
|||||||
public List<Condition> Conditions { get; set; }
|
public List<Condition> Conditions { get; set; }
|
||||||
public List<MyCore.Interfaces.Models.Action> Actions { get; set; }
|
public List<MyCore.Interfaces.Models.Action> Actions { get; set; }
|
||||||
public List<string> DevicesIds { get; set; }
|
public List<string> DevicesIds { get; set; }
|
||||||
|
public List<DeviceDetailDTO> Devices { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -100,6 +100,7 @@ namespace MyCore.Interfaces.Models
|
|||||||
CreatedDate = CreatedDate,
|
CreatedDate = CreatedDate,
|
||||||
UpdatedDate = UpdatedDate,
|
UpdatedDate = UpdatedDate,
|
||||||
Triggers = Triggers,
|
Triggers = Triggers,
|
||||||
|
Actions = Actions,
|
||||||
Devices = devicesDetail,
|
Devices = devicesDetail,
|
||||||
ProgrammedMode = ProgrammedMode,
|
ProgrammedMode = ProgrammedMode,
|
||||||
GeolocalizedMode = GeolocalizedMode
|
GeolocalizedMode = GeolocalizedMode
|
||||||
|
|||||||
@ -58,7 +58,7 @@ namespace MyCore.Interfaces.Models
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public AutomationDetailDTO ToDetailDTO()
|
public AutomationDetailDTO ToDetailDTO(List<DeviceDetailDTO> devicesDetail)
|
||||||
{
|
{
|
||||||
return new AutomationDetailDTO()
|
return new AutomationDetailDTO()
|
||||||
{
|
{
|
||||||
@ -71,7 +71,8 @@ namespace MyCore.Interfaces.Models
|
|||||||
Triggers = Triggers,
|
Triggers = Triggers,
|
||||||
Conditions = Conditions,
|
Conditions = Conditions,
|
||||||
Actions = Actions,
|
Actions = Actions,
|
||||||
DevicesIds = DevicesIds
|
DevicesIds = DevicesIds,
|
||||||
|
Devices = devicesDetail
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,13 +24,15 @@ namespace MyCore.Service.Controllers
|
|||||||
public class AutomationController : ControllerBase
|
public class AutomationController : ControllerBase
|
||||||
{
|
{
|
||||||
private HomeDatabaseService _HomeDatabaseService;
|
private HomeDatabaseService _HomeDatabaseService;
|
||||||
|
private DeviceDatabaseService _DeviceDatabaseService;
|
||||||
private AutomationDatabaseService _AutomationDatabaseService;
|
private AutomationDatabaseService _AutomationDatabaseService;
|
||||||
private readonly IMqttClientService _mqttClientService;
|
private readonly IMqttClientService _mqttClientService;
|
||||||
//private readonly IMqttOnlineClientService _mqttOnlineClientService;
|
//private readonly IMqttOnlineClientService _mqttOnlineClientService;
|
||||||
|
|
||||||
public AutomationController(HomeDatabaseService homeDatabaseService, AutomationDatabaseService automationDatabaseService, MqttClientServiceProvider provider)//, MqttClientOnlineServiceProvider onlineProvider)
|
public AutomationController(HomeDatabaseService homeDatabaseService, DeviceDatabaseService deviceDatabaseService, AutomationDatabaseService automationDatabaseService, MqttClientServiceProvider provider)//, MqttClientOnlineServiceProvider onlineProvider)
|
||||||
{
|
{
|
||||||
this._HomeDatabaseService = homeDatabaseService;
|
this._HomeDatabaseService = homeDatabaseService;
|
||||||
|
this._DeviceDatabaseService = deviceDatabaseService;
|
||||||
this._AutomationDatabaseService = automationDatabaseService;
|
this._AutomationDatabaseService = automationDatabaseService;
|
||||||
this._mqttClientService = provider.MqttClientService;
|
this._mqttClientService = provider.MqttClientService;
|
||||||
//this._mqttOnlineClientService = onlineProvider.MqttOnlineClientService;
|
//this._mqttOnlineClientService = onlineProvider.MqttOnlineClientService;
|
||||||
@ -80,7 +82,17 @@ namespace MyCore.Service.Controllers
|
|||||||
if (automation == null)
|
if (automation == null)
|
||||||
throw new KeyNotFoundException("Automation not found");
|
throw new KeyNotFoundException("Automation not found");
|
||||||
|
|
||||||
return new OkObjectResult(automation.ToDetailDTO());
|
List<Device> devices = new List<Device>();
|
||||||
|
foreach (var deviceId in automation.DevicesIds)
|
||||||
|
{
|
||||||
|
Device device = _DeviceDatabaseService.GetById(deviceId);
|
||||||
|
if (device != null)
|
||||||
|
{
|
||||||
|
devices.Add(device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new OkObjectResult(automation.ToDetailDTO(devices.Select(d => d.ToDTO()).ToList()));
|
||||||
}
|
}
|
||||||
catch (ArgumentNullException ex)
|
catch (ArgumentNullException ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -54,8 +54,12 @@ namespace MyCore.Service.Services
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<string> devicesIds = alarmModeCreateOrUpdateDetailDTO.Triggers.Select(t => t.DeviceId).ToList();
|
List<string> devicesIdsTriggers = alarmModeCreateOrUpdateDetailDTO.Triggers.Select(t => t.DeviceId).ToList();
|
||||||
alarmMode.DevicesIds = devicesIds;
|
alarmMode.DevicesIds = devicesIdsTriggers;
|
||||||
|
|
||||||
|
List<string> devicesIdsActions = alarmModeCreateOrUpdateDetailDTO.Actions.Select(t => t.DeviceId).ToList();
|
||||||
|
alarmMode.DevicesIds.AddRange(devicesIdsActions);
|
||||||
|
|
||||||
if (create)
|
if (create)
|
||||||
alarmMode = _AlarmDatabaseService.Create(alarmMode);
|
alarmMode = _AlarmDatabaseService.Create(alarmMode);
|
||||||
else
|
else
|
||||||
@ -63,7 +67,7 @@ namespace MyCore.Service.Services
|
|||||||
|
|
||||||
// List devices for DTO (only)
|
// List devices for DTO (only)
|
||||||
List<Device> devices = new List<Device>();
|
List<Device> devices = new List<Device>();
|
||||||
foreach (var deviceId in devicesIds)
|
foreach (var deviceId in alarmMode.DevicesIds)
|
||||||
{
|
{
|
||||||
Device device = _DeviceDatabaseService.GetById(deviceId);
|
Device device = _DeviceDatabaseService.GetById(deviceId);
|
||||||
if (device != null)
|
if (device != null)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user