From af80aa3d4c6156a6cd5d5e0bd5d8ba9b08c0f387 Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Fri, 21 Jun 2024 13:31:43 +0800 Subject: [PATCH] Add: [ALAS] Switch.wait() --- module/ui/switch.py | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/module/ui/switch.py b/module/ui/switch.py index fd13c61c9..95304fe41 100644 --- a/module/ui/switch.py +++ b/module/ui/switch.py @@ -137,14 +137,14 @@ class Switch: current = self.get(main=main) logger.attr(self.name, current) - # Handle additional popups - if self.handle_additional(main=main): - continue - # End if current == state: return changed + # Handle additional popups + if self.handle_additional(main=main): + continue + # Warning if current == 'unknown': if warning_show_timer.reached(): @@ -165,3 +165,36 @@ class Switch: changed = True return changed + + def wait(self, main, skip_first_screenshot=True): + """ + Wait until any state activated + + Args: + main (ModuleBase): + skip_first_screenshot: + + Returns: + bool: If success + """ + timeout = Timer(2, count=6).start() + while 1: + if skip_first_screenshot: + skip_first_screenshot = False + else: + main.device.screenshot() + + # Detect + current = self.get(main=main) + logger.attr(self.name, current) + + # End + if current != 'unknown': + return True + if timeout.reached(): + logger.warning(f'{self.name} wait activated timeout') + return False + + # Handle additional popups + if self.handle_additional(main=main): + continue