def load_app(self) -> bool: my_logger(handler_level=int(self.args.debug)) if self.args.config: self.config_name = self.args.config if path.isfile(self.config_name): self.myp = MyPSACC.load_config(name=self.config_name) elif self.args.web_conf: self.is_good = False return False else: raise FileNotFoundError(self.config_name) atexit.register(self.save_config) self.myp.set_record(self.args.record) Charging.elec_price = ElecPrice.read_config() if self.args.offline: logger.info("offline mode") self.is_good = True else: self.is_good = False try: self.is_good = self.myp.manager.refresh_token_now() if self.is_good: logger.info(str(self.myp.get_vehicles())) except OAuthError: if self.args.mail and self.args.password: self.myp.connect(self.args.mail, self.args.password) logger.info(str(self.myp.get_vehicles())) self.is_good = True else: self.is_good = False logger.error( "Please reconnect by going to config web page") if self.args.refresh: self.myp.info_refresh_rate = self.args.refresh * 60 if self.is_good: self.myp.start_refresh_thread() if self.is_good: self.start_remote_control() elif not self.args.web_conf: raise ConnectionError self.save_config() return True
parser.add_argument("-r", "--record", help="save vehicle data to db", action='store_true') parser.add_argument("-R", "--refresh", help="refresh vehicles status every x min", type=int) parser.add_argument("-m", "--mail", default=environ.get('USER_EMAIL', None), help="set the email address") parser.add_argument("-P", "--password", default=environ.get('USER_PASSWORD', None), help="set the password") parser.add_argument("--remote-disable", help="disable remote control", action='store_true') parser.add_argument("--offline", help="offline limited mode", action='store_true') parser.add_argument("-b", "--base-path", help="base path for web app", default="/") return parser.parse_args() # noqa: MC0001 if __name__ == "__main__": if sys.version_info < (3, 6): raise RuntimeError("This application requires Python 3.6+") args = parse_args() my_logger(handler_level=args.debug) if is_port_in_use(args.listen, int(args.port)): logger.error(" Address already in use") sys.exit(1) logger.info("server start") if args.config: CONFIG_NAME = args.config.name web.app.myp = MyPSACC.load_config(name=CONFIG_NAME) atexit.register(web.app.myp.save_config) web.app.myp.set_record(args.record) Charging.elec_price = ElecPrice.read_config() if args.offline: logger.info("offline mode") else: try: web.app.myp.refresh_token()
pass test_fct() test_fct() try: test_fct() raise Exception("It should have raise RateLimitException") except RateLimitException: pass def test_parse_apk(self): from libs.psa.setup.app_decoder import get_content_from_apk filename = "mypeugeot.apk" try: os.remove(filename) except FileNotFoundError: pass assert get_content_from_apk(filename, "FR") assert github_file_need_to_be_downloaded(GITHUB_USER, GITHUB_REPO, "", filename) is False def test_file_need_to_be_updated(self): filename = "mypeugeot.apk" with open(filename, "w") as f: f.write(" ") assert github_file_need_to_be_downloaded(GITHUB_USER, GITHUB_REPO, "", filename) is True if __name__ == '__main__': my_logger(handler_level=os.environ.get("DEBUG_LEVEL", 20)) unittest.main()