mirror of
https://bitbucket.org/myhomie/mycorerepository.git
synced 2025-12-06 01:31:19 +00:00
MC fix return value automation get all + test if active automation in action service + add try catch for one automation
This commit is contained in:
parent
2f10433f94
commit
58fa2a2b4b
@ -8,11 +8,8 @@ namespace MyCore.Interfaces.DTO
|
||||
public class GroupSummaryDTO
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
||||
public string UserId { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Type { get; set; }
|
||||
public bool IsAlarm { get; set; }
|
||||
}
|
||||
@ -20,9 +17,7 @@ namespace MyCore.Interfaces.DTO
|
||||
public class GroupDetailDTO : GroupSummaryDTO
|
||||
{
|
||||
public DateTime CreatedDate { get; set; }
|
||||
|
||||
public DateTime UpdatedDate { get; set; }
|
||||
|
||||
public List<DeviceDetailDTO> Devices { get; set; }
|
||||
}
|
||||
|
||||
|
||||
@ -51,6 +51,7 @@ namespace MyCore.Interfaces.Models
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Active = Active,
|
||||
UserId = UserId,
|
||||
CreatedDate = CreatedDate,
|
||||
UpdatedDate = UpdatedDate,
|
||||
@ -66,6 +67,7 @@ namespace MyCore.Interfaces.Models
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Active = Active,
|
||||
UserId = UserId,
|
||||
CreatedDate = CreatedDate,
|
||||
UpdatedDate = UpdatedDate,
|
||||
|
||||
@ -40,7 +40,7 @@ namespace MyCore.Service.Controllers
|
||||
/// Get all automations for the specified user
|
||||
/// </summary>
|
||||
/// <param name="userId">Id of user</param>
|
||||
[ProducesResponseType(typeof(List<RoomSummaryDTO>), 200)]
|
||||
[ProducesResponseType(typeof(List<AutomationDTO>), 200)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpGet("{userId}")]
|
||||
public ObjectResult GetAll(string userId)
|
||||
|
||||
@ -44,7 +44,7 @@ namespace MyCore.Services.Devices
|
||||
|
||||
if (currentProvider != null)
|
||||
{
|
||||
var automations = _AutomationDatabaseService.GetByProvider(currentProvider.Id);
|
||||
var automations = _AutomationDatabaseService.GetActiveByProvider(currentProvider.Id);
|
||||
|
||||
deviceTrigger = _DeviceDatabaseService.GetByName(deviceServiceName).FirstOrDefault();
|
||||
|
||||
@ -57,6 +57,7 @@ namespace MyCore.Services.Devices
|
||||
{
|
||||
foreach (var automation in automations)
|
||||
{
|
||||
try {
|
||||
// todo check if not null and if more than one element
|
||||
if (deviceTrigger != null && automation.Triggers.Any(t => t.DeviceId == deviceTrigger.Id))
|
||||
{
|
||||
@ -127,7 +128,8 @@ namespace MyCore.Services.Devices
|
||||
// take raw request and send it !
|
||||
RawRequestMQTT rawRequestMQTT = JsonConvert.DeserializeObject<RawRequestMQTT>(action.RawRequest);
|
||||
|
||||
if (rawRequestMQTT!= null) {
|
||||
if (rawRequestMQTT != null)
|
||||
{
|
||||
// SEND REQUEST
|
||||
System.Console.WriteLine($"Send raw request mqtt! topic:{rawRequestMQTT.topic} - message: {rawRequestMQTT.message}");
|
||||
MqttClientService.PublishMessage(rawRequestMQTT.topic, rawRequestMQTT.message);
|
||||
@ -149,7 +151,9 @@ namespace MyCore.Services.Devices
|
||||
try
|
||||
{
|
||||
ActionOnZigbee2Mqtt(actionDeviceToTest, action, DeviceNameForAction);
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Console.WriteLine($"ActionOnZigbee2Mqtt result in error: {ex}");
|
||||
}
|
||||
break;
|
||||
@ -188,6 +192,7 @@ namespace MyCore.Services.Devices
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) { System.Console.WriteLine($"Exeption in one of automation logic - {ex}"); }
|
||||
}
|
||||
// Update last state of devices
|
||||
deviceTrigger.LastStateDate = DateTime.Now;
|
||||
|
||||
@ -33,6 +33,11 @@ namespace MyCore.Services.MyControlPanel
|
||||
return _Automations.Find<Automation>(a => a.Triggers.Any(t => t.ProviderId == id)).ToList();
|
||||
}
|
||||
|
||||
public List<Automation> GetActiveByProvider(string id)
|
||||
{
|
||||
return _Automations.Find<Automation>(a => a.Triggers.Any(t => t.ProviderId == id) && a.Active).ToList();
|
||||
}
|
||||
|
||||
public bool IsExist(string id)
|
||||
{
|
||||
return _Automations.Find<Automation>(d => d.Id == id).FirstOrDefault() != null ? true : false;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user