public async Task Apply(IScene scene) { var controllers = new Dictionary <String, IDeviceController>(); try{ var commands = scene.Commands.OrderBy(x => x.ExecutionOrder).ToList(); foreach (var command in commands) { var device = command.Device; var deviceType = device.DeviceType; Console.WriteLine($"{device.DeviceType} : {device.Name} - {command.CommandName} ({command.Parameters})"); if (!controllers.ContainsKey(deviceType)) { Console.WriteLine($"Adding Controller for {deviceType}"); controllers.Add(deviceType, deviceControllerFactory.GetDeviceManager(device)); } var deviceController = controllers[deviceType]; try{ await deviceController.ExecuteCommand(command); }catch (Exception ex) { Console.WriteLine(ex); } } }catch (Exception ex) { Console.WriteLine(ex); } }
public async Task DeviceCommand(string deviceName, ExecuteCommandRequest commandRequest) { var device = deviceRepo.GetByName(deviceName); var manager = _dcf.GetDeviceManager(device); var command = new ha.sdk.Command { Device = device, CommandName = commandRequest.Command, Parameters = commandRequest.Parameters }; await manager.ExecuteCommand(command); }