Fix group action not working

This commit is contained in:
Thomas Fransolet 2023-08-31 17:10:30 +02:00
parent adb38f842b
commit 48e6fd872e
3 changed files with 13 additions and 15 deletions

View File

@ -233,7 +233,7 @@ namespace MyCore.Service.Controllers.Helpers
} }
} }
public static void ActionOnZigbee2Mqtt(Device device, Interfaces.Models.Action action) public static void ActionOnZigbee2Mqtt(Device device, Interfaces.Models.Action action, string deviceOrGroupNameForAction)
{ {
var request = ""; var request = "";
var buildRequest = new Dictionary<string, object>(); var buildRequest = new Dictionary<string, object>();
@ -372,13 +372,11 @@ namespace MyCore.Service.Controllers.Helpers
request = JsonConvert.SerializeObject(buildRequest); request = JsonConvert.SerializeObject(buildRequest);
var nameToSend = device.NameForAction == null ? device.Name : device.NameForAction;
// SEND REQUEST // SEND REQUEST
//var requestToSend = $"Send request ! zigbee2mqtt/{deviceNameForAction}/set/{request}"; //var requestToSend = $"Send request ! zigbee2mqtt/{deviceNameForAction}/set/{request}";
System.Console.WriteLine($"Send request ! zigbee2mqtt/{nameToSend}/set/{request}"); System.Console.WriteLine($"Send request ! zigbee2mqtt/{deviceOrGroupNameForAction}/set/{request}");
MqttClientService.PublishMessage($"zigbee2mqtt/{nameToSend}/set", request); MqttClientService.PublishMessage($"zigbee2mqtt/{deviceOrGroupNameForAction}/set", request);
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -184,7 +184,7 @@ namespace MyCore.Service.Services
foreach (var action in alarmMode.Actions) foreach (var action in alarmMode.Actions)
{ {
var DeviceNameForAction = ""; var deviceOrGroupNameForAction = "";
Device actionDeviceToTest = new Device(); Device actionDeviceToTest = new Device();
// Retrieve action type // Retrieve action type
@ -194,14 +194,14 @@ namespace MyCore.Service.Services
var deviceAction = _DeviceDatabaseService.GetById(action.DeviceId); var deviceAction = _DeviceDatabaseService.GetById(action.DeviceId);
var providerActionTest = _ProviderDatabaseService.GetById(action.ProviderId); var providerActionTest = _ProviderDatabaseService.GetById(action.ProviderId);
DeviceNameForAction = deviceAction.Name; deviceOrGroupNameForAction = deviceAction.NameForAction == null ? deviceAction.Name : deviceAction.NameForAction;
actionDeviceToTest = deviceAction; actionDeviceToTest = deviceAction;
System.Console.WriteLine($"We get a device action ! Name={deviceAction.Name} Type={deviceAction.Type}"); System.Console.WriteLine($"We get a device action ! Name={deviceAction.Name} Type={deviceAction.Type}");
System.Console.WriteLine($"Check action provider type ! Type={providerActionTest.Type} Name={providerActionTest.Name}"); System.Console.WriteLine($"Check action provider type ! Type={providerActionTest.Type} Name={providerActionTest.Name}");
break; break;
case ActionType.GROUP: case ActionType.GROUP:
var groupAction = _GroupDatabaseService.GetById(action.GroupId); var groupAction = _GroupDatabaseService.GetById(action.GroupId);
DeviceNameForAction = groupAction.Name; deviceOrGroupNameForAction = groupAction.Name;
System.Console.WriteLine($"We get a group action ! Name={groupAction.Name} Type={groupAction.Type}"); System.Console.WriteLine($"We get a group action ! Name={groupAction.Name} Type={groupAction.Type}");
System.Console.WriteLine($"Check action zigbeeGroupAction type ! Type={groupAction.Type}"); System.Console.WriteLine($"Check action zigbeeGroupAction type ! Type={groupAction.Type}");
@ -235,7 +235,7 @@ namespace MyCore.Service.Services
case ProviderType.zigbee2mqtt: case ProviderType.zigbee2mqtt:
try try
{ {
DevicesHelper.ActionOnZigbee2Mqtt(actionDeviceToTest, action); DevicesHelper.ActionOnZigbee2Mqtt(actionDeviceToTest, action, deviceOrGroupNameForAction);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -245,7 +245,7 @@ namespace MyCore.Service.Services
case ProviderType.meross: case ProviderType.meross:
try try
{ {
DevicesHelper.ActionOnMeross(_DeviceDatabaseService, actionDeviceToTest, action, DeviceNameForAction); DevicesHelper.ActionOnMeross(_DeviceDatabaseService, actionDeviceToTest, action, deviceOrGroupNameForAction);
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -120,7 +120,7 @@ namespace MyCore.Service.Services
public static void HandleAction(string homeId, Interfaces.Models.Action action, ProviderDatabaseService providerDatabaseService, DeviceDatabaseService deviceDatabaseService, GroupDatabaseService groupDatabaseService) public static void HandleAction(string homeId, Interfaces.Models.Action action, ProviderDatabaseService providerDatabaseService, DeviceDatabaseService deviceDatabaseService, GroupDatabaseService groupDatabaseService)
{ {
var DeviceNameForAction = ""; var deviceOrGroupNameForAction = "";
Device actionDeviceToTest = new Device(); Device actionDeviceToTest = new Device();
// Retrieve action type // Retrieve action type
@ -130,14 +130,14 @@ namespace MyCore.Service.Services
var deviceAction = deviceDatabaseService.GetById(action.DeviceId); var deviceAction = deviceDatabaseService.GetById(action.DeviceId);
var providerActionTest = providerDatabaseService.GetById(action.ProviderId); var providerActionTest = providerDatabaseService.GetById(action.ProviderId);
DeviceNameForAction = deviceAction.Name; deviceOrGroupNameForAction = deviceAction.NameForAction == null ? deviceAction.Name : deviceAction.NameForAction;
actionDeviceToTest = deviceAction; actionDeviceToTest = deviceAction;
System.Console.WriteLine($"We get a device action ! Name={deviceAction.Name} Type={deviceAction.Type}"); System.Console.WriteLine($"We get a device action ! Name={deviceAction.Name} Type={deviceAction.Type}");
System.Console.WriteLine($"Check action provider type ! Type={providerActionTest.Type} Name={providerActionTest.Name}"); System.Console.WriteLine($"Check action provider type ! Type={providerActionTest.Type} Name={providerActionTest.Name}");
break; break;
case ActionType.GROUP: case ActionType.GROUP:
var groupAction = groupDatabaseService.GetById(action.GroupId); var groupAction = groupDatabaseService.GetById(action.GroupId);
DeviceNameForAction = groupAction.Name; deviceOrGroupNameForAction = groupAction.Name;
System.Console.WriteLine($"We get a group action ! Name={groupAction.Name} Type={groupAction.Type}"); System.Console.WriteLine($"We get a group action ! Name={groupAction.Name} Type={groupAction.Type}");
System.Console.WriteLine($"Check action zigbeeGroupAction type ! Type={groupAction.Type}"); System.Console.WriteLine($"Check action zigbeeGroupAction type ! Type={groupAction.Type}");
@ -171,7 +171,7 @@ namespace MyCore.Service.Services
case ProviderType.zigbee2mqtt: case ProviderType.zigbee2mqtt:
try try
{ {
DevicesHelper.ActionOnZigbee2Mqtt(actionDeviceToTest, action); DevicesHelper.ActionOnZigbee2Mqtt(actionDeviceToTest, action, deviceOrGroupNameForAction);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -181,7 +181,7 @@ namespace MyCore.Service.Services
case ProviderType.meross: case ProviderType.meross:
try try
{ {
DevicesHelper.ActionOnMeross(deviceDatabaseService, actionDeviceToTest, action, DeviceNameForAction); DevicesHelper.ActionOnMeross(deviceDatabaseService, actionDeviceToTest, action, deviceOrGroupNameForAction);
} }
catch (Exception ex) catch (Exception ex)
{ {