Skip to content

Commit

Permalink
Merge pull request #134 from itchannel/1.23
Browse files Browse the repository at this point in the history
1.23
  • Loading branch information
itchannel authored Dec 1, 2021
2 parents 02a2dee + 1302de6 commit af41530
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 63 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
- https://github.com/pinballnewf - Figuring out the application ID issue
- https://github.com/degrashopper - Fixing 401 error for certain installs
- https://github.com/tonesto7 - Extra window statuses and sensors
- https://github.com/JacobWasFramed - Updated unit conversions

## 1.23 Breaking Change
The way the units work has been changed so if updating please go to "Integrations" and click options on fordpass and choose your preferred units (miles/km etc) and restart HA. Not doing this will result in an error!!

## Install
Use HACS and add as a custom repo. Once the integration is installed go to your integrations and follow the configuration options to specify the below:
Expand Down
21 changes: 19 additions & 2 deletions custom_components/fordpass/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@
UpdateFailed,
)

from .const import CONF_UNIT, DEFAULT_UNIT, DOMAIN, MANUFACTURER, REGION, VEHICLE, VIN
from .const import (
CONF_DISTANCE_UNIT,
CONF_PRESSURE_UNIT,
DEFAULT_DISTANCE_UNIT,
DEFAULT_PRESSURE_UNIT,
DOMAIN,
MANUFACTURER,
REGION,
VEHICLE,
VIN,
)
from .fordpass_new import Vehicle

CONFIG_SCHEMA = vol.Schema({DOMAIN: vol.Schema({})}, extra=vol.ALLOW_EXTRA)
Expand Down Expand Up @@ -90,7 +100,14 @@ async def async_clear_tokens_service(service_call):


async def async_update_options(hass, config_entry):
options = {CONF_UNIT: config_entry.data.get(CONF_UNIT, DEFAULT_UNIT)}
options = {
CONF_PRESSURE_UNIT: config_entry.data.get(
CONF_PRESSURE_UNIT, DEFAULT_PRESSURE_UNIT
)
}
options[CONF_DISTANCE_UNIT] = config_entry.data.get(
CONF_DISTANCE_UNIT, DEFAULT_DISTANCE_UNIT
)
hass.config_entries.async_update_entry(config_entry, options=options)


Expand Down
23 changes: 17 additions & 6 deletions custom_components/fordpass/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
from homeassistant.core import callback

from .const import ( # pylint:disable=unused-import
CONF_UNIT,
CONF_UNITS,
DEFAULT_UNIT,
CONF_DISTANCE_UNIT,
CONF_PRESSURE_UNIT,
DEFAULT_DISTANCE_UNIT,
DEFAULT_PRESSURE_UNIT,
DISTANCE_UNITS,
DOMAIN,
PRESSURE_UNITS,
REGION,
REGION_OPTIONS,
VIN,
Expand Down Expand Up @@ -94,9 +97,17 @@ async def async_step_init(self, user_input=None):
return self.async_create_entry(title="", data=user_input)
options = {
vol.Optional(
CONF_UNIT,
default=self.config_entry.options.get(CONF_UNIT, DEFAULT_UNIT),
): vol.In(CONF_UNITS)
CONF_PRESSURE_UNIT,
default=self.config_entry.options.get(
CONF_PRESSURE_UNIT, DEFAULT_PRESSURE_UNIT
),
): vol.In(PRESSURE_UNITS),
vol.Optional(
CONF_DISTANCE_UNIT,
default=self.config_entry.options.get(
CONF_DISTANCE_UNIT, DEFAULT_DISTANCE_UNIT
),
): vol.In(DISTANCE_UNITS),
}

return self.async_show_form(step_id="init", data_schema=vol.Schema(options))
Expand Down
10 changes: 7 additions & 3 deletions custom_components/fordpass/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@

VEHICLE = "Ford Vehicle"

DEFAULT_UNIT = "metric"
CONF_UNIT = "units"
DEFAULT_PRESSURE_UNIT = "kPa"
DEFAULT_DISTANCE_UNIT = "km"

CONF_UNITS = ["imperial", "metric"]
CONF_PRESSURE_UNIT = "pressure_unit"
CONF_DISTANCE_UNIT = "distance_unit"

PRESSURE_UNITS = ["PSI", "kPa"]
DISTANCE_UNITS = ["mi", "km"]


REGION = "region"
Expand Down
2 changes: 1 addition & 1 deletion custom_components/fordpass/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"config_flow": true,
"documentation": "https://github.com/itchannel/fordpass-ha",
"issue_tracker": "https://github.com/itchannel/fordpass-ha/issues",
"version": "0.1.22",
"version": "0.1.23",
"requirements": ["dotted==0.1.8"],
"ssdp": [],
"zeroconf": [],
Expand Down
64 changes: 20 additions & 44 deletions custom_components/fordpass/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from homeassistant.util import Throttle, dt

from . import FordPassEntity
from .const import CONF_UNIT, DOMAIN, SENSORS
from .const import CONF_DISTANCE_UNIT, CONF_PRESSURE_UNIT, DOMAIN, SENSORS

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -43,15 +43,18 @@ def __init__(self, coordinator, sensor, options):
def get_value(self, ftype):
if ftype == "state":
if self.sensor == "odometer":
if self.options[CONF_UNIT] == "imperial":
if self.options[CONF_DISTANCE_UNIT] == "mi":
return round(
float(self.coordinator.data[self.sensor]["value"]) / 1.60934
)
else:
return self.coordinator.data[self.sensor]["value"]
elif self.sensor == "fuel":
if self.coordinator.data[self.sensor] == None:
return None
if self.options[CONF_DISTANCE_UNIT] == "mi":
self.coordinator.data["fuel"]["distanceToEmpty"] = round(
float(self.coordinator.data["fuel"]["distanceToEmpty"])
/ 1.60934
)
return round(self.coordinator.data[self.sensor]["fuelLevel"])
elif self.sensor == "battery":
return self.coordinator.data[self.sensor]["batteryHealth"]["value"]
Expand Down Expand Up @@ -120,7 +123,7 @@ def get_value(self, ftype):
return "Inactive"
elif ftype == "measurement":
if self.sensor == "odometer":
if self.options[CONF_UNIT] == "imperial":
if self.options[CONF_DISTANCE_UNIT] == "mi":
return "mi"
else:
return "km"
Expand Down Expand Up @@ -169,48 +172,21 @@ def get_value(self, ftype):
return self.coordinator.data[self.sensor].items()
elif self.sensor == "tirePressure":
if self.coordinator.data["TPMS"] != None:
if self.options[CONF_UNIT] == "imperial":

if self.options[CONF_PRESSURE_UNIT] == "PSI":
sval = 0.1450377377
rval = 1
else:
sval = 1
return {
"leftFrontTirePressure": round(
float(
self.coordinator.data["TPMS"]["leftFrontTirePressure"][
"value"
]
or 0
)
* sval
),
"rightFrontTirePressure": round(
float(
self.coordinator.data["TPMS"]["rightFrontTirePressure"][
"value"
]
or 0
)
* sval
),
"outerLeftRearTirePressure": round(
float(
self.coordinator.data["TPMS"][
"outerLeftRearTirePressure"
]["value"]
or 0
)
* sval
),
"outerRightRearTirePressure": round(
float(
self.coordinator.data["TPMS"][
"outerRightRearTirePressure"
]["value"]
or 0
)
* sval
),
}
rval = 6.8947572932
tirepress = {}
for key, value in self.coordinator.data["TPMS"].items():
if "TirePressure" in key and value is not None:
if "recommended" in key:
tirepress[key] = round(float(value["value"]) * rval)
else:
tirepress[key] = round(float(value["value"]) * sval)
return tirepress
return None
elif self.sensor == "gps":
if self.coordinator.data[self.sensor] == None:
Expand Down
3 changes: 2 additions & 1 deletion custom_components/fordpass/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"step": {
"init": {
"data": {
"units": "Unit of Measurement"
"pressure_unit": "Unit of Pressure",
"distance_unit": "Unit of Distance"
},
"description": "Configure fordpass options"
}
Expand Down
13 changes: 7 additions & 6 deletions custom_components/fordpass/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
},
"options": {
"step": {
"init": {
"data": {
"units": "Unit of Measurement"
},
"description": "Configure fordpass options"
}
"init": {
"data": {
"pressure_unit": "Unit of Pressure",
"distance_unit": "Unit of Distance"
},
"description": "Configure fordpass options"
}
}
},
"title": "FordPass"
Expand Down
8 changes: 8 additions & 0 deletions info.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@

# **Changelog**
### Version 1.23
**Breaking Change**

When installing this new version please go to "integrations" and click configure on Fordpass and choose your preferred units. Not doing this will result in an error!!

- Fixed tyre pressure status when sensor missing or broke
- Add DistanceToEmpty Imperial Conversion (Thanks @JacobWasFramed )
- Seperated pressure and distance measurement unit selection (Thanks @JacobWasFramed)
### Version 1.22
- Fix for custom config locations on certain HA installs

Expand Down

0 comments on commit af41530

Please sign in to comment.