Lazy init modules

Fixes "ERROR: Only nop and sig tag can be recevied before authentication." message before authentification

Signed-off-by: Dinolek <github@dinolek.me>
This commit is contained in:
Dinolek 2024-07-07 13:22:32 +02:00
parent ec43594ccd
commit f2a04c833c
No known key found for this signature in database
GPG key ID: 077B32AEC0CB2507
2 changed files with 19 additions and 11 deletions

View file

@ -7,6 +7,8 @@
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!! # GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
import logging import logging
from functools import cached_property
from edlclient.Library.utils import LogBase from edlclient.Library.utils import LogBase
try: try:
@ -52,25 +54,31 @@ class modules(metaclass=LogBase):
self.__logger.addHandler(fh) self.__logger.addHandler(fh)
self.options = {} self.options = {}
self.devicemodel = devicemodel self.devicemodel = devicemodel
self.generic = None
@cached_property
def generic(self):
try: 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: except Exception as e:
self.error(e) self.error(e)
pass return None
self.ops = None
@cached_property
def ops(self):
try: try:
self.ops = oneplus(fh=self.fh, projid=self.devicemodel, serial=self.serial, return oneplus(fh=self.fh, projid=self.devicemodel, serial=self.serial, loglevel=self.__logger.loglevel,
supported_functions=self.supported_functions, args=self.args, loglevel=loglevel) supported_functions=self.supported_functions, args=self.args)
except Exception as e: except Exception as e:
self.error(e) self.error(e)
pass return None
self.xiaomi = None
@cached_property
def xiaomi(self):
try: try:
self.xiaomi = xiaomi(fh=self.fh) return xiaomi(fh=self.fh)
except Exception as e: except Exception as e:
self.error(e) self.error(e)
pass return None
def addpatch(self): def addpatch(self):
if self.ops is not None: if self.ops is not None:
@ -116,7 +124,6 @@ class modules(metaclass=LogBase):
return self.generic.oem_unlock(enable) return self.generic.oem_unlock(enable)
elif self.ops is not None and command == "ops": elif self.ops is not None and command == "ops":
if self.devicemodel is not None: if self.devicemodel is not None:
enable = False
partition = "param" partition = "param"
if "enable" in options: if "enable" in options:
enable = True enable = True

View file

@ -915,6 +915,7 @@ class firehose(metaclass=LogBase):
except Exception as err: # pylint: disable=broad-except except Exception as err: # pylint: disable=broad-except
self.modules = None self.modules = None
if self.modules.edlauth(): if self.modules.edlauth():
self.info("EDL Authenticated successfully.")
rsp = self.xmlsend(connectcmd) rsp = self.xmlsend(connectcmd)
return rsp.resp return rsp.resp
else: else: