Skip to content

Commit

Permalink
Reworked Fuel sensor to work for EV and Hybrid. Better time display f…
Browse files Browse the repository at this point in the history
…or Trip Duration under elVeh. Returning 0 for the kW conversion if the values are 0 and the math doesn't happen.
  • Loading branch information
SquidBytes committed Oct 30, 2023
1 parent 0b54dd0 commit b09c420
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
31 changes: 22 additions & 9 deletions custom_components/fordpass/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ def get_value(self, ftype):
return self.data.get("odometer", {}).get("value")
#return self.data.get("odometer", {}).get("value", {})
if self.sensor == "fuel":
fuel_level = self.data.get("fuelLevel", {}).get("value", 0)
fuel_level = self.data.get("fuelLevel", {}).get("value")
if fuel_level is not None:
return round(fuel_level)
battery_soc = self.data.get("xevBatteryStateOfCharge", {}).get("value", 0)
battery_soc = self.data.get("xevBatteryStateOfCharge", {}).get("value")
if battery_soc is not None:
return round(battery_soc)
return None
Expand Down Expand Up @@ -171,10 +171,16 @@ def get_value(self, ftype):
return { "Ambient Temp": ambient_temp}
return None
if self.sensor == "fuel":
if "fuelRange" in self.data:
return {"fuelRange" : self.units.length(self.data.get("fuelRange", {}).get("value", 0),UnitOfLength.KILOMETERS)}
if "xevBatteryRange" in self.data:
return {"batteryRange": self.units.length(self.data.get("xevBatteryRange", {}).get("value", 0),UnitOfLength.KILOMETERS)}
fuel = {}
fuel_range = self.data.get("fuelRange", {}).get("value", 0)
battery_range = self.data.get("xevBatteryRange", {}).get("value", 0)
if fuel_range != 0:
# Display fuel range for both Gas and Hybrid (assuming its not 0)
fuel["fuelRange"] = self.units.length(fuel_range,UnitOfLength.KILOMETERS)
if battery_range != 0:
# Display Battery range for EV and Hybrid
fuel["batteryRange"] = self.units.length(battery_range,UnitOfLength.KILOMETERS)
return fuel
if self.sensor == "battery":
return {
"Battery Voltage": self.data.get("batteryVoltage", {}).get("value", 0)
Expand Down Expand Up @@ -259,9 +265,12 @@ def get_value(self, ftype):
elecs["Battery Amperage"] = float(self.data.get("xevBatteryIoCurrent", {}).get("value", 0))
batt_amps = elecs.get("Battery Amperage", 0)

# Returning 0 in else - to prevent attribute from not displaying
if "xevBatteryIoCurrent" in self.data and "xevBatteryVoltage" in self.data:
if batt_volt != 0 and batt_amps != 0:
elecs["Battery kW"] = round((batt_volt * batt_amps) / 1000, 2)
else:
elecs["Battery kW"] = 0

if "xevTractionMotorVoltage" in self.data:
elecs["Motor Voltage"] = float(self.data.get("xevTractionMotorVoltage", {}).get("value", 0))
Expand All @@ -271,10 +280,12 @@ def get_value(self, ftype):
elecs["Motor Amperage"] = float(self.data.get("xevTractionMotorCurrent", {}).get("value", 0))
motor_amps = elecs.get("Motor Amperage", 0)

# This will make Motor kW not display if vehicle is not in use. Not sure if that is bad practice
# Returning 0 in else - to prevent attribute from not displaying
if "xevTractionMotorVoltage" in self.data and "xevTractionMotorCurrent" in self.data:
if motor_volt != 0 and motor_amps != 0:
elecs["Motor kW"] = round((motor_volt * motor_amps) / 1000, 2)
else:
elecs["Motor kW"] = 0

# tripXevBatteryChargeRegenerated should be a previous FordPass feature called "Driving Score". A % based on how much regen vs brake you use
if "tripXevBatteryChargeRegenerated" in self.data:
Expand Down Expand Up @@ -304,7 +315,7 @@ def get_value(self, ftype):
if "outside_air_ambient_temperature" in tripData:
elecs["Trip Outside Air Ambient Temp"] = self.units.temperature(tripData["outside_air_ambient_temperature"], UnitOfTemperature.CELSIUS)
if "trip_duration" in tripData:
elecs["Trip Duration"] = tripData["trip_duration"] / 3600
elecs["Trip Duration"] = str(dt.parse_duration(str(tripData["trip_duration"])))
if "cabin_temperature" in tripData:
elecs["Trip Cabin Temp"] = self.units.temperature(tripData["cabin_temperature"], UnitOfTemperature.CELSIUS)
if "energy_consumed" in tripData:
Expand Down Expand Up @@ -351,10 +362,12 @@ def get_value(self, ftype):
cs["Charging Amperage"] = float(self.data.get("xevBatteryChargerCurrentOutput", {}).get("value", 0))
ch_amps = cs["Charging Amperage"]

# This will make Charging kW not display if vehicle is not charging. Not sure if that is bad practice by having it pop in and out
# Returning 0 in else - to prevent attribute from not displaying
if "xevBatteryChargerVoltageOutput" in self.data and "xevBatteryChargerCurrentOutput" in self.data:
if ch_volt != 0 and ch_amps != 0:
cs["Charging kW"] = round((ch_volt * ch_amps) / 1000, 2)
else:
cs["Charging kW"] = 0

if "xevBatteryTemperature" in self.data:
cs["Battery Temperature"] = self.units.temperature(self.data.get("xevBatteryTemperature", {}).get("value", 0), UnitOfTemperature.CELSIUS)
Expand Down
5 changes: 4 additions & 1 deletion info.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
- Handle missing countdownTimer variable
- Handle missing events dictionary
- Temporary fix for elveh errors
- Added more Trip Data to elVeh (will asses to determine if previous Trip scores can be removed)
- Added more Trip Data to elVeh (will assess to determine if previous Trip scores can be removed)
- Trip Speed Score
- Trip Deceleration Score
- Trip Acceleration Score
- Trip Electrical Efficiency (unsure what this value is, adding it to get more data)
- Fix for fuel not displaying properly for EV's (will assess to determine if duplicate values in other sensors can be removed)
- Better display for Trip Duration under elVeh
- elVeh kW conversions will display 0 if voltage or amperage is 0
### Version 1.60
- Versioning issue 1.59 is 1.60
### Version 1.59
Expand Down

0 comments on commit b09c420

Please sign in to comment.