From aa5aecb205d80e2fad522448d8770591ef746475 Mon Sep 17 00:00:00 2001 From: gryf Date: Wed, 7 Jul 2021 17:32:58 +0200 Subject: [PATCH] DRY. Simplifying get_status method. --- linak_ctrl.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/linak_ctrl.py b/linak_ctrl.py index 2cc0a2d..6649f6b 100755 --- a/linak_ctrl.py +++ b/linak_ctrl.py @@ -128,20 +128,17 @@ class LinakDevice: self._dev.detach_kernel_driver(0) def get_position(self, args): - if args.loop: - try: - while True: - report = self._get_report() - LOG.warning('Position: %s, height: %.2fcm, moving: %s', - report.position, report.position_in_cm, - report.moving) - time.sleep(0.2) - except KeyboardInterrupt: - return - else: - report = self._get_report() - LOG.warning('Position: %s, height: %.2fcm, moving: %s', - report.position, report.position_in_cm, report.moving) + try: + while True: + report = self._get_report() + LOG.warning('Position: %s, height: %.2fcm, moving: %s', + report.position, report.position_in_cm, + report.moving) + if not args.loop: + break + time.sleep(0.2) + except KeyboardInterrupt: + return def move(self, args): retry_count = 3