mirror of
https://github.com/flobz/psa_car_controller.git
synced 2026-08-23 09:56:14 +00:00
fix ModuleNotFoundError & clean up
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -75,3 +75,4 @@ class OauthAPIClient(ApiClient):
|
||||
self.configuration.refresh_callback()
|
||||
else:
|
||||
raise e
|
||||
return None
|
||||
|
||||
@@ -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)
|
||||
|
||||
+18
-3
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user