diff --git a/src/vac.py b/src/vac.py index 83d0f43..32dc90b 100755 --- a/src/vac.py +++ b/src/vac.py @@ -12,6 +12,9 @@ import os from robovac.robovac import Robovac +DEFAULT_TIME = 20 + + stop_event = asyncio.Event() @@ -81,7 +84,14 @@ async def async_pause(r: Robovac): await r.async_pause(callback) -async def async_main(device_id,ip,local_code,time,go_home,debug,pause): +async def async_main( + device_id, + ip, + local_code, + time=DEFAULT_TIME, + go_home=False, + pause=False +): asyncio.get_event_loop().add_signal_handler(signal.SIGTERM, signal_handler) asyncio.get_event_loop().add_signal_handler(signal.SIGINT, signal_handler) r = Robovac(device_id,ip,local_code) @@ -89,29 +99,31 @@ async def async_main(device_id,ip,local_code,time,go_home,debug,pause): await asyncio.sleep(2) - if debug: + if not go_home and not pause: while not stop_event.is_set(): - if not go_home: - print("Auto cleaning") - await stepper(time) - if go_home: - print("Go home") - if pause: - print("Pause") - else: - while not stop_event.is_set(): - if not go_home: - await async_auto_clean(r, time = int(time)) - await async_go_home(r) - if go_home: - await async_go_home(r) - if pause: - await async_pause(r) + await async_auto_clean(r, time = int(time)) + await async_go_home(r) + stop_event.set() - if not debug: - if stop_event.is_set() and not r.go_home and not pause: await async_go_home(r) - if r._connected: await r.async_disconnect() + if go_home and not pause: + while not stop_event.is_set(): + await async_go_home(r) + stop_event.set() + + + if pause and not go_home: + while not stop_event.is_set(): + await async_pause(r) + stop_event.set() + + + if not r.go_home and not pause: + await async_go_home(r) + + + if r._connected: + await r.async_disconnect() def main(*args, **kwargs): @@ -141,19 +153,15 @@ def main(*args, **kwargs): defaults = {} - if not use_config: - print("Configuration skipped") - - parser = argparse.ArgumentParser(description="Control a Robovac device.") parser.add_argument('-c', '--config', help="Path to config file", default=early_args.config) parser.add_argument('--device_id', help="Device ID", default=None if early_args.device_id else defaults.get('device_id')) parser.add_argument('--ip', help="Device IP address", default=None if early_args.ip else defaults.get('ip')) parser.add_argument('--local_code', help="Secret key obtained from eufy", default=None if early_args.local_code else defaults.get('local_code')) - parser.add_argument('--time', '-t', type=int, default=20, help="Cleaning time in minutes") - parser.add_argument('--pause','-p', action='store_true', dest="pause", default=False, help="Pause vacuum") + parser.add_argument('--time', '-t', type=int, default=DEFAULT_TIME, help="Cleaning time in minutes") parser.add_argument('--home', '-b', action='store_true', dest="go_home", default=False, help="Go home") - parser.add_argument('--debug','-d', action='store_true', dest="debug", default=False, help="Enter debugging mode (won't send commands to vacuum)") + parser.add_argument('--pause','-p', action='store_true', dest="pause", default=False, help="Pause vacuum") + # parser.add_argument('--debug','-d', action='store_true', dest="debug", default=False, help="Enter debugging mode (won't send commands to vacuum)") parser.add_argument('--verbose','-v', action='store_true', dest="verbose", default=False, help="Enable verbose logs") parser.add_argument('--quiet','-q', action='store_true', dest="quiet", default=False, help="Quiet logs") args = parser.parse_args() @@ -165,17 +173,21 @@ def main(*args, **kwargs): logging.basicConfig(level=logging.DEBUG) elif args.quiet: logging.basicConfig(level=logging.CRITICAL) + sys.stdout = open(os.devnull, 'w') else: logging.basicConfig(level=logging.INFO) + if not use_config: print("Configuration skipped") + + missing = [key for key in ['device_id', 'ip', 'local_code'] if getattr(args, key) is None] if missing: parser.error(f"Missing required argument(s): {', '.join(missing)}") try: - asyncio.run(async_main(args.device_id, args.ip, args.local_code, args.time, args.go_home,args.debug,args.pause)) + asyncio.run(async_main(args.device_id, args.ip, args.local_code, args.time, args.go_home,args.pause)) except Exception as e: if args.debug or args.verbose: print(e)