diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ca4581e..1bb311c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,3 +3,4 @@ repos: rev: 1.3.1 # The version of Prospector to use, at least 1.1.7 hooks: - id: prospector + language: system diff --git a/libs/oauth.py b/libs/oauth.py index 5698147..f2445a7 100644 --- a/libs/oauth.py +++ b/libs/oauth.py @@ -75,3 +75,4 @@ class OauthAPIClient(ApiClient): self.configuration.refresh_callback() else: raise e + return None diff --git a/my_psacc.py b/my_psacc.py index db25e36..6aa36ea 100644 --- a/my_psacc.py +++ b/my_psacc.py @@ -331,6 +331,7 @@ class MyPSACC: except IndexError: logger.error(traceback.format_exc()) logger.error("Can't get charge hour: %s", hour_str) + return None def get_charge_status(self, vin): data = self.get_vehicle_info(vin) diff --git a/otp/otp.py b/otp/otp.py index 37f6bd7..617d879 100644 --- a/otp/otp.py +++ b/otp/otp.py @@ -16,6 +16,7 @@ from mylogger import logger from . import oaep from .load import IWData + # pylint: disable=too-many-instance-attributes,invalid-name def etree_to_dict(t): @@ -169,7 +170,7 @@ class Otp: return etree_to_dict(ElT.XML(raw_xml))["ActionFinalize"] except KeyError: logger.debug(raw_xml) - raise ValueError("Bad response from server") + raise ValueError("Bad response from server") from KeyError def activation_start(self): param = {"action": "ActionSetup", "mode": self.mode, "id": self.data.iwid, "lastsync": self.data.iwTsync, @@ -214,7 +215,7 @@ class Otp: try: self.defi = str(xml["defi"]) except KeyError: - raise ConfigException + raise ConfigException from KeyError if "J" in xml: logger.debug("Need another otp request") return Otp.OTP_TWICE @@ -301,10 +302,24 @@ def save_otp(obj, filename="otp.bin"): pickle.dump(obj, output) +class RenameUnpickler(pickle.Unpickler): + def find_class(self, module, name): + renamed_module = module + if module == 'otp.Otp': + renamed_module = "otp.otp" + elif module == 'otp.Tokenizer': + renamed_module = "otp.tokenizer" + + return super().find_class(renamed_module, name) + + def load_otp(filename="otp.bin"): try: with open(filename, 'rb') as input_file: - return pickle.load(input_file) + try: + return pickle.load(input_file) + except ModuleNotFoundError: + return RenameUnpickler(input_file).load() except FileNotFoundError: logger.debug(traceback.format_exc()) return None