From f2a04c833c0fc2e96349dc5728f862b81693fb5d Mon Sep 17 00:00:00 2001 From: Dinolek Date: Sun, 7 Jul 2024 13:22:32 +0200 Subject: [PATCH] Lazy init modules Fixes "ERROR: Only nop and sig tag can be recevied before authentication." message before authentification Signed-off-by: Dinolek --- edlclient/Library/Modules/init.py | 29 ++++++++++++++++++----------- edlclient/Library/firehose.py | 1 + 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/edlclient/Library/Modules/init.py b/edlclient/Library/Modules/init.py index 619bd8f..6d69c76 100644 --- a/edlclient/Library/Modules/init.py +++ b/edlclient/Library/Modules/init.py @@ -7,6 +7,8 @@ # GPLv3 and has to be open sourced under GPLv3 as well. !!!!! import logging +from functools import cached_property + from edlclient.Library.utils import LogBase try: @@ -52,25 +54,31 @@ def __init__(self, fh, serial: int, supported_functions, loglevel, devicemodel: self.__logger.addHandler(fh) self.options = {} self.devicemodel = devicemodel - self.generic = None + + @cached_property + def generic(self): try: - self.generic = generic(fh=self.fh, serial=self.serial, args=self.args, loglevel=loglevel) + return generic(fh=self.fh, serial=self.serial, args=self.args, loglevel=self.__logger.loglevel) except Exception as e: self.error(e) - pass - self.ops = None + return None + + @cached_property + def ops(self): try: - self.ops = oneplus(fh=self.fh, projid=self.devicemodel, serial=self.serial, - supported_functions=self.supported_functions, args=self.args, loglevel=loglevel) + return oneplus(fh=self.fh, projid=self.devicemodel, serial=self.serial, loglevel=self.__logger.loglevel, + supported_functions=self.supported_functions, args=self.args) except Exception as e: self.error(e) - pass - self.xiaomi = None + return None + + @cached_property + def xiaomi(self): try: - self.xiaomi = xiaomi(fh=self.fh) + return xiaomi(fh=self.fh) except Exception as e: self.error(e) - pass + return None def addpatch(self): if self.ops is not None: @@ -116,7 +124,6 @@ def run(self, command, args): return self.generic.oem_unlock(enable) elif self.ops is not None and command == "ops": if self.devicemodel is not None: - enable = False partition = "param" if "enable" in options: enable = True diff --git a/edlclient/Library/firehose.py b/edlclient/Library/firehose.py index c9ab0f0..c903c3d 100755 --- a/edlclient/Library/firehose.py +++ b/edlclient/Library/firehose.py @@ -915,6 +915,7 @@ def configure(self, lvl): except Exception as err: # pylint: disable=broad-except self.modules = None if self.modules.edlauth(): + self.info("EDL Authenticated successfully.") rsp = self.xmlsend(connectcmd) return rsp.resp else: