Skip to content

Commit

Permalink
Fix for null batt_volt
Browse files Browse the repository at this point in the history
  • Loading branch information
itchannel committed Oct 23, 2023
1 parent 1c245bd commit 28451af
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions custom_components/fordpass/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,9 @@ def get_value(self, ftype):
elecs["Battery Amperage"] = float(self.data.get("xevBatteryIoCurrent", {}).get("value", 0))
batt_amps = elecs.get("Battery Amperage", 0)

if batt_volt != 0 and batt_amps != 0:
elecs["Battery kW"] = round((batt_volt * batt_amps) / 1000, 2)
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)

if "xevTractionMotorVoltage" in self.data:
elecs["Motor Voltage"] = float(self.data.get("xevTractionMotorVoltage", {}).get("value", 0))
Expand All @@ -271,8 +272,9 @@ def get_value(self, ftype):
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
if motor_volt != 0 and motor_amps != 0:
elecs["Motor kW"] = round((motor_volt * motor_amps) / 1000, 2)
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)

# 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 @@ -338,8 +340,9 @@ def get_value(self, ftype):
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
if ch_volt != 0 and ch_amps != 0:
cs["Charging kW"] = round((ch_volt * ch_amps) / 1000, 2)
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)

if "xevBatteryTemperature" in self.data:
cs["Battery Temperature"] = self.units.temperature(self.data.get("xevBatteryTemperature", {}).get("value", 0), UnitOfTemperature.CELSIUS)
Expand Down

0 comments on commit 28451af

Please sign in to comment.