Skip to content

Commit

Permalink
new line length
Browse files Browse the repository at this point in the history
  • Loading branch information
fredriklj committed Dec 28, 2024
1 parent c07baf6 commit f5a4843
Showing 1 changed file with 14 additions and 37 deletions.
51 changes: 14 additions & 37 deletions pyporscheconnectapi/vehicle.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Models the state of a Porsche Connect vehicle."""

from __future__ import annotations

import datetime
Expand Down Expand Up @@ -89,10 +90,7 @@ def has_remote_services(self) -> bool:
@property
def has_electric_drivetrain(self) -> bool:
"""Return True if vehicle is equipped with a high voltage battery."""
return (
self.data["modelType"]["engine"] == "BEV"
or self.data["modelType"]["engine"] == "PHEV"
)
return self.data["modelType"]["engine"] == "BEV" or self.data["modelType"]["engine"] == "PHEV"

@property
def main_battery_level(self) -> int:
Expand All @@ -105,10 +103,7 @@ def main_battery_level(self) -> int:
@property
def has_ice_drivetrain(self) -> bool:
"""Return True if vehicle has an internal combustion engine."""
return (
self.data["modelType"]["engine"] == "PHEV"
or self.data["modelType"]["engine"] == "COMBUSTION"
)
return self.data["modelType"]["engine"] == "PHEV" or self.data["modelType"]["engine"] == "COMBUSTION"

@property
def has_remote_climatisation(self) -> bool:
Expand All @@ -125,10 +120,7 @@ def has_direct_charge(self) -> bool:
@property
def direct_charge_on(self) -> bool:
"""Return True if direct charging is enabled."""
return (
self.data.get("BATTERY_CHARGING_STATE", {}).get("directChargingState")
== "ENABLED_ON"
)
return self.data.get("BATTERY_CHARGING_STATE", {}).get("directChargingState") == "ENABLED_ON"

@property
def privacy_mode(self) -> bool:
Expand All @@ -138,6 +130,8 @@ def privacy_mode(self) -> bool:
@property
def remote_climatise_on(self) -> bool:
"""Return True if remote climatisation is on."""
_LOGGER.debug("Remote climatisation is: %s", self.data.get("CLIMATIZER_STATE", {}).get("isOn"))

return self.data.get("CLIMATIZER_STATE", {}).get("isOn")

@property
Expand All @@ -150,22 +144,14 @@ def vehicle_closed(self) -> bool:
"""Return True if all doors and lids are closed."""
return not bool(
sum(
[
self.data[key]["isOpen"]
for key in self.data
if key.startswith("OPEN_STATE_")
],
[self.data[key]["isOpen"] for key in self.data if key.startswith("OPEN_STATE_")],
),
)

@property
def doors_and_lids(self) -> bool:
"""Return list of all doors and lids and their status."""
dl = [
{key: "Open" if self.data[key]["isOpen"] is True else "Closed"}
for key in self.data
if key.startswith("OPEN_STATE_")
]
dl = [{key: "Open" if self.data[key]["isOpen"] is True else "Closed"} for key in self.data if key.startswith("OPEN_STATE_")]
return dict(map(dict.popitem, dl))

@property
Expand All @@ -176,11 +162,7 @@ def tire_pressure_status(self) -> bool:
not sorted(
map(
abs,
[
tire_pressure_status[key]["differenceBar"]
for key in tire_pressure_status
if key.endswith("Tire")
],
[tire_pressure_status[key]["differenceBar"] for key in tire_pressure_status if key.endswith("Tire")],
),
)[-1]
> TIRE_PRESSURE_TOLERANCE
Expand All @@ -202,7 +184,8 @@ def charging_target(self) -> bool | None:
if self.data.get("CHARGING_PROFILES"):
charging_profiles = self.data["CHARGING_PROFILES"]["list"]
active_charging_profile_id = self.data["BATTERY_CHARGING_STATE"].get(
"activeProfileId", None,
"activeProfileId",
None,
)

if active_charging_profile_id is None:
Expand Down Expand Up @@ -337,9 +320,7 @@ def _update_vehicle_data(self) -> None:

bdata = {k: self.status[k] for k in BASE_DATA}

bdata["name"] = (
bdata["customName"] if "customName" in bdata else bdata["modelName"]
)
bdata["name"] = bdata["customName"] if "customName" in bdata else bdata["modelName"]

_LOGGER.debug(
"Got base data for vehicle '%s': %s",
Expand All @@ -348,9 +329,7 @@ def _update_vehicle_data(self) -> None:
)

if "measurements" in self.status:
tdata = [
m for m in self.status["measurements"] if m["status"]["isEnabled"]
]
tdata = [m for m in self.status["measurements"] if m["status"]["isEnabled"]]

for m in tdata:
mdata[m["key"]] = m["value"]
Expand All @@ -365,9 +344,7 @@ def _update_vehicle_data(self) -> None:
if "BATTERY_CHARGING_STATE" in mdata:
if "chargingRate" in mdata["BATTERY_CHARGING_STATE"]:
# Convert charging rate from km/min to km/h
mdata["BATTERY_CHARGING_STATE"]["chargingRate"] = (
mdata["BATTERY_CHARGING_STATE"]["chargingRate"] * 60
)
mdata["BATTERY_CHARGING_STATE"]["chargingRate"] = mdata["BATTERY_CHARGING_STATE"]["chargingRate"] * 60
else:
# Charging is currently not ongoing, but we should still feed some data to the sensor
mdata["BATTERY_CHARGING_STATE"]["chargingRate"] = 0
Expand Down

0 comments on commit f5a4843

Please sign in to comment.