diff --git a/commands2/commandscheduler.py b/commands2/commandscheduler.py index 7eba7a4..be362bc 100644 --- a/commands2/commandscheduler.py +++ b/commands2/commandscheduler.py @@ -334,6 +334,12 @@ def unregisterSubsystem(self, *subsystems: Subsystem) -> None: for subsystem in subsystems: self._subsystems.pop(subsystem, None) + def getAllSubsystems(self) -> tuple[Subsystem, ...]: + """ + Gets all registered subsystems as an immutable tuple. + """ + return tuple(self._subsystems.keys()) + def unregisterAllSubsystems(self): """ Un-registers all registered Subsystems with the scheduler. All currently registered subsystems diff --git a/tests/test_command_schedule.py b/tests/test_command_schedule.py index 62d2182..68d9ffe 100644 --- a/tests/test_command_schedule.py +++ b/tests/test_command_schedule.py @@ -88,3 +88,21 @@ def test_notScheduledCancel(scheduler: commands2.CommandScheduler): command = commands2.Command() scheduler.cancel(command) + +def test_getAllSubystems(scheduler: commands2.CommandScheduler): + sub1 = commands2.Subsystem() + sub1.setName("test123") + sub2 = commands2.Subsystem() + sub2.setName("hey") + start_spying_on(sub1) + start_spying_on(sub2) + scheduler.registerSubsystem(sub1) + scheduler.registerSubsystem(sub2) + sublist = scheduler.getAllSubsystems() + con1 = sublist[0].getName() == "test123" + con2 = sublist[0].getName() == "hey" + assert con1 or con2 + if(con1): + assert sublist[1].getName() == "hey" + else: + assert sublist[1].getName() == "test123"