From 9133802d189095ce32edd745475cbdfafc0a199e Mon Sep 17 00:00:00 2001 From: 332FG Raven <332fg.raven@gmail.com> Date: Fri, 26 Apr 2024 20:43:06 -0700 Subject: [PATCH] Support for checking if Ground Control has password set --- dcs/groundcontrol.py | 7 +++++++ tests/test_mission.py | 3 +++ 2 files changed, 10 insertions(+) diff --git a/dcs/groundcontrol.py b/dcs/groundcontrol.py index e702697a..7cf5464c 100644 --- a/dcs/groundcontrol.py +++ b/dcs/groundcontrol.py @@ -53,6 +53,10 @@ def unlock(self, coalition: Coalition, role: GroundControlRole) -> None: role_password = self._find_role_password(role) role_password[coalition] = None + def is_locked(self, coalition: Coalition, role: GroundControlRole) -> bool: + role_password = self._find_role_password(role) + return coalition in role_password and role_password[coalition] is not None + def dict(self) -> Dict[str, Dict[str, str]]: d: Dict[str, Any] = {} for coalition in [Coalition.Red, Coalition.Blue, Coalition.Neutral]: @@ -115,6 +119,9 @@ def lock(self, coalition: Coalition, role: GroundControlRole, password: str) -> def unlock(self, coalition: Coalition, role: GroundControlRole) -> None: self.passwords.unlock(coalition, role) + def is_locked(self, coalition: Coalition, role: GroundControlRole) -> bool: + return self.passwords.is_locked(coalition, role) + def dict(self): return { "isPilotControlVehicles": self.pilot_can_control_vehicles, diff --git a/tests/test_mission.py b/tests/test_mission.py index 2f7878a0..ef962912 100644 --- a/tests/test_mission.py +++ b/tests/test_mission.py @@ -1386,6 +1386,9 @@ def test_ground_control_password(self) -> None: m.groundControl.lock(Coalition.Blue, GroundControlRole.OBSERVER, "p-observer-blue") m.groundControl.lock(Coalition.Blue, GroundControlRole.TACTICAL_COMMANDER, "p-tc-blue") + self.assertTrue(m.groundControl.is_locked(Coalition.Blue, GroundControlRole.TACTICAL_COMMANDER)) + self.assertFalse(m.groundControl.is_locked(Coalition.Red, GroundControlRole.TACTICAL_COMMANDER)) + self.assertIn(Coalition.Blue.value, m.groundControl.dict()["passwords"][GroundControlRole.TACTICAL_COMMANDER.value]) self.assertIn(Coalition.Blue.value,