Skip to content

Commit

Permalink
Merge pull request #142 from itchannel/1.27
Browse files Browse the repository at this point in the history
1.27
  • Loading branch information
itchannel authored Dec 16, 2021
2 parents f07b2a7 + 9f471c0 commit b026d8b
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 14 deletions.
13 changes: 12 additions & 1 deletion custom_components/fordpass/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,15 @@ async def validate_input(hass: core.HomeAssistant, data):

try:
result = await hass.async_add_executor_job(vehicle.auth)

except Exception as ex:
raise InvalidAuth from ex

try:
result3 = await hass.async_add_executor_job(vehicle.vehicles)
#raise InvalidVin
except Exception as ex:
raise InvalidVin from ex


if not result:
_LOGGER.error("Failed to authenticate with fordpass")
Expand Down Expand Up @@ -72,6 +78,8 @@ async def async_step_user(self, user_input=None):
errors["base"] = "cannot_connect"
except InvalidAuth:
errors["base"] = "invalid_auth"
except InvalidVin:
errors["base"] = "invalid_vin"
except Exception: # pylint: disable=broad-except
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
Expand Down Expand Up @@ -119,3 +127,6 @@ class CannotConnect(exceptions.HomeAssistantError):

class InvalidAuth(exceptions.HomeAssistantError):
"""Error to indicate there is invalid auth."""

class InvalidVin(exceptions.HomeAssistantError):
"""Error to indicate the wrong vin"""
45 changes: 42 additions & 3 deletions custom_components/fordpass/fordpass_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,6 @@ def status(self):
else:
r.raise_for_status()

def messages(self):
self.__acquireToken()

def messages(self):
self.__acquireToken()
headers = {
Expand All @@ -245,6 +242,48 @@ def messages(self):
else:
_LOGGER.debug(r.text)
r.raise_for_status()

def vehicles(self):
self.__acquireToken()

headers = {
**apiHeaders,
"Auth-Token": self.token,
"Application-Id": self.region,
}
r = session.get(
"https://services.cx.ford.com/api/dashboard/v1/users/vehicles", headers=headers
)
if r.status_code == 200:
result = r.json()


_LOGGER.debug(result)
return result["vehicleCapabilities"]
else:
_LOGGER.debug(r.text)
r.raise_for_status()

def vehicles(self):
self.__acquireToken()

headers = {
**apiHeaders,
"Auth-Token": self.token,
"Application-Id": self.region,
}
r = session.get(
"https://services.cx.ford.com/api/dashboard/v1/users/vehicles",
headers=headers,
)
if r.status_code == 200:
result = r.json()

_LOGGER.debug(result)
return result["vehicleCapabilities"]
else:
_LOGGER.debug(r.text)
r.raise_for_status()

def guardStatus(self):
# WIP current being tested
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.25",
"version": "0.1.27",
"requirements": ["dotted==0.1.8"],
"ssdp": [],
"zeroconf": [],
Expand Down
23 changes: 14 additions & 9 deletions custom_components/fordpass/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ def __init__(self, coordinator, sensor, options):
def get_value(self, ftype):
if ftype == "state":
if self.sensor == "odometer":
if self.options[CONF_DISTANCE_UNIT] == "mi":
return round(
float(self.coordinator.data[self.sensor]["value"]) / 1.60934
)
if self.options[CONF_DISTANCE_UNIT] != None:
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"]
else:
return self.coordinator.data[self.sensor]["value"]
elif self.sensor == "fuel":
if self.options[CONF_DISTANCE_UNIT] == "mi":
self.coordinator.data["fuel"]["distanceToEmpty"] = round(
float(self.coordinator.data["fuel"]["distanceToEmpty"])
/ 1.60934
)
if self.coordinator.data[self.sensor] == None:
return None
return round(self.coordinator.data[self.sensor]["fuelLevel"])
elif self.sensor == "battery":
return self.coordinator.data[self.sensor]["batteryHealth"]["value"]
Expand Down Expand Up @@ -168,6 +168,11 @@ def get_value(self, ftype):
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 self.coordinator.data[self.sensor].items()
elif self.sensor == "battery":
return {
Expand Down
1 change: 1 addition & 0 deletions custom_components/fordpass/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"error": {
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"invalid_vin": "[%key:common::config_flow::error::invalid_vin%]",
"unknown": "[%key:common::config_flow::error::unknown%]"
},
"abort": {
Expand Down
1 change: 1 addition & 0 deletions custom_components/fordpass/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"error": {
"cannot_connect": "Failed to connect",
"invalid_auth": "Invalid authentication",
"invalid_vin": "Vin not found",
"unknown": "Unexpected error"
},
"step": {
Expand Down
3 changes: 3 additions & 0 deletions info.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@

# **Changelog**
### Version 1.27
- Fix fuel level error
- Add code for Vin debugging
### Version 1.25
- Updated user agent
- Added messages sensor to show current messages in fordpass
Expand Down

0 comments on commit b026d8b

Please sign in to comment.