Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions packages/modules/vehicles/bmwbc/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,10 @@ async def _fetch_soc(self,
log.debug("dataPath=" + str(DATA_PATH))
DATA_PATH.mkdir(parents=True, exist_ok=True)
except Exception as e:
log.error("init: dataPath creation failed, dataPath: " +
str(DATA_PATH) + ", error=" + str(e))
if user_id not in self._store:
self._store[user_id] = init_store()
return 0, 0.0, 0
raise Exception("init: dataPath creation failed, dataPath: " +
str(DATA_PATH) + ", error=" + str(e))

# if self._storeFile is None:
if user_id not in self._primary_vehicle_id:
Expand All @@ -185,10 +184,6 @@ async def _fetch_soc(self,
raise RequestFailed("sequence problem: secondary starts without preceding primary")

try:
# initialize return values in case we get into trouble
soc = 0
range = 0.0
soc_tsX = 0.0
self._login_required[user_id] = False

if captcha_token != "SECONDARY":
Expand Down Expand Up @@ -236,13 +231,13 @@ async def _fetch_soc(self,
log.info("authenticate via current token set")
expires_at = datetime.fromisoformat(self._store[user_id]['expires_at'])
self._auth[user_id] = MyBMWAuthentication(
user_id,
password,
Regions.REST_OF_WORLD,
refresh_token=self._store[user_id]['refresh_token'],
access_token=self._store[user_id]['access_token'],
expires_at=expires_at,
hcaptcha_token=captcha_token)
user_id,
password,
Regions.REST_OF_WORLD,
refresh_token=self._store[user_id]['refresh_token'],
access_token=self._store[user_id]['access_token'],
expires_at=expires_at,
hcaptcha_token=captcha_token)
else:
# no token, authenticate via user_id, password and captcha_token
log.info("authenticate via userid, password, captcha token")
Expand Down Expand Up @@ -393,10 +388,6 @@ async def _fetch_soc(self,
self._auth.pop(user_id, None)
self._clconf.pop(user_id, None)
self._account.pop(user_id, None)
soc = 0
range = 0.0
soc_tsX = datetime.timestamp(datetime.now())
# raise RequestFailed("SoC Request failed:\n" + str(err))
raise Exception("SoC Request failed") from err
return soc, range, soc_tsX

Expand Down
10 changes: 5 additions & 5 deletions packages/modules/vehicles/http/soc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
def fetch_soc(config: HttpSocSetup) -> CarState:
soc_url = config.configuration.soc_url
range_url = config.configuration.range_url

if soc_url is None or soc_url == "none":
log.warning("http_soc: soc_url not defined - set soc to 0")
soc = 0
raise Exception("http_soc: soc_url not defined - using default soc value")
else:
soc_text = req.get_http_session().get(soc_url, timeout=5).text
soc = int(soc_text)

if range_url is None or range_url == "none":
log.warning("http_soc: range_url not defined - set range to 0.0")
range = float(0)
return CarState(soc)
else:
range_text = req.get_http_session().get(range_url, timeout=5).text
range = float(range_text)
return CarState(soc, range)
return CarState(soc, range)


def create_vehicle(vehicle_config: HttpSocSetup, vehicle: int):
Expand Down
19 changes: 7 additions & 12 deletions packages/modules/vehicles/leaf/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,13 @@ async def requestSoc(leaf: pycarwings3.Leaf):
log.debug("vehicle%s: Update not successful" % (vehicle))
return status

try:
leaf = await getNissanSession() # start HTTPS session with Nissan server
soc_range = await readSoc(leaf) # read old SoC & range values from server
await asyncio.sleep(1) # give Nissan server some time
status = await requestSoc(leaf) # Nissan server to request new values from vehicle
if status is not None: # was update of values successful?
await asyncio.sleep(1) # give Nissan server some time
soc_range = await readSoc(leaf) # final read of SoC & range from server
except pycarwings3.CarwingsError as e:
log.info("vehicle%s: SoC & range request not successful" % (vehicle))
log.info(e)
soc_range = CarState(0.0, 0.0)
leaf = await getNissanSession() # start HTTPS session with Nissan server
soc_range = await readSoc(leaf) # read old SoC & range values from server
await asyncio.sleep(1) # give Nissan server some time
status = await requestSoc(leaf) # Nissan server to request new values from vehicle
if status is not None: # was update of values successful?
await asyncio.sleep(1) # give Nissan server some time
soc_range = await readSoc(leaf) # final read of SoC & range from server
return soc_range


Expand Down
6 changes: 1 addition & 5 deletions packages/modules/vehicles/vwgroup/vwgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,7 @@ async def request_data(self, library) -> Union[int, float, str]:
self.soc_tsX = datetime.timestamp(soc_tsdtL)
self.soc_ts = datetime.strftime(soc_tsdtL, ts_fmt)
except Exception as e:
self.log.exception("soc/range/soc_ts field missing exception: e=" + str(e))
self.soc = 0
self.range = 0.0
self.soc_ts = ""
self.soc_tsX = time()
raise Exception("soc/range/soc_ts field missing exception: e=" + str(e))

# decision logic - shall a new refreshToken be stored?
self.store_refreshToken = False
Expand Down