public static List <string> ListCommands(string deviceId) { var Challenge = new Challenge(); var Commands = Challenge.Commands(); var Devices = Challenge.Devices(); var Device = new Device(); foreach (var device in Devices) { if (device.Id == deviceId) { Device = device; } else { Device = new Device(); return(null); } } var Capabilities = Device.Capabilities; var DeviceCommands = new List <string>(); foreach (var command in Commands) { if (command.Active == true) { foreach (string capability in Capabilities) { if (command.Type == capability) { DeviceCommands.Add(command.Name); } } } } return(DeviceCommands); }