Skip to content

Commit

Permalink
Merge pull request #277 from itchannel/1.48
Browse files Browse the repository at this point in the history
1.48
  • Loading branch information
itchannel authored Jul 28, 2023
2 parents 2f2f7c6 + d9783b7 commit 5cb7a5e
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 20 deletions.
1 change: 1 addition & 0 deletions custom_components/fordpass/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def refresh_status(hass, service, coordinator):
_LOGGER.debug("Invalid VIN")
elif status == 200:
_LOGGER.debug("Refresh Sent")



def clear_tokens(hass, service, coordinator):
Expand Down
42 changes: 31 additions & 11 deletions custom_components/fordpass/fordpass_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
}

baseUrl = "https://usapi.cv.ford.com/api"

guardUrl = "https://api.mps.ford.com/api"
ssoUrl = "https://sso.ci.ford.com"

session = requests.Session()

Expand All @@ -48,6 +48,7 @@ def __init__(
self.password = password
self.saveToken = saveToken
self.region = region_lookup[region]
self.region2 = region
self.vin = vin
self.token = None
self.expires = None
Expand Down Expand Up @@ -82,14 +83,14 @@ def auth(self):
}
code1 = ''.join(random.choice(string.ascii_lowercase) for i in range(43))
code_verifier = self.generate_hash(code1)
url1 = "https://sso.ci.ford.com/v1.0/endpoint/default/authorize?redirect_uri=fordapp://userauthorized&response_type=code&scope=openid&max_age=3600&client_id=9fb503e0-715b-47e8-adfd-ad4b7770f73b&code_challenge=" + code_verifier + "&code_challenge_method=S256"
url1 = f"{ssoUrl}/v1.0/endpoint/default/authorize?redirect_uri=fordapp://userauthorized&response_type=code&scope=openid&max_age=3600&client_id=9fb503e0-715b-47e8-adfd-ad4b7770f73b&code_challenge={code_verifier}&code_challenge_method=S256"
r = session.get(
url1,
headers=headers,
)

test = re.findall('data-ibm-login-url="(.*)"\s', r.text)[0]
nextUrl = "https://sso.ci.ford.com" + test
nextUrl = ssoUrl + test


# Auth Step2
Expand Down Expand Up @@ -157,7 +158,7 @@ def auth(self):
}

r = session.post(
"https://sso.ci.ford.com/oidc/endpoint/default/token",
f"{ssoUrl}/oidc/endpoint/default/token",
headers = headers,
data = data

Expand All @@ -176,7 +177,7 @@ def auth(self):
data = {"ciToken": access_token}
headers = {**apiHeaders, "Application-Id": self.region}
r = session.post(
"https://api.mps.ford.com/api/token/v2/cat-with-ci-access-token",
f"{guardUrl}/token/v2/cat-with-ci-access-token",
data=json.dumps(data),
headers=headers,
)
Expand All @@ -201,7 +202,7 @@ def refreshToken(self, token):
headers = {**apiHeaders, "Application-Id": self.region}

r = session.post(
"https://api.mps.ford.com/api/token/v2/cat-with-refresh-token",
f"{guardUrl}/token/v2/cat-with-refresh-token",
data=json.dumps(data),
headers=headers,
)
Expand Down Expand Up @@ -339,16 +340,32 @@ def messages(self):
def vehicles(self):
self.__acquireToken()

if (self.region2 == "Australia"):
countryheader = "AUS"
elif (self.region2 == "North America & Canada"):
countryheader = "USA"
elif (self.region2 == "UK&Europe"):
countryheader = "GBR"
else:
countryheader = "USA"
headers = {
**apiHeaders,
"Auth-Token": self.token,
"Application-Id": self.region,
"Countrycode": countryheader,
"Locale": "EN-US"
}
r = session.get(
"https://services.cx.ford.com/api/dashboard/v1/users/vehicles",


data = {
"dashboardRefreshRequest":"All"
}
r = session.post(
guardUrl + "/expdashboard/v1/details/",
headers=headers,
data=json.dumps(data)
)
if r.status_code == 200:
if r.status_code == 207:
result = r.json()

_LOGGER.debug(result)
Expand Down Expand Up @@ -481,6 +498,9 @@ def __requestAndPoll(self, method, url):

if command.status_code == 200:
result = command.json()
return self.__pollStatus(url, result["commandId"])
if "commandId" in result:
return self.__pollStatus(url, result["commandId"])
else:
return False
else:
command.raise_for_status()
return False
7 changes: 5 additions & 2 deletions custom_components/fordpass/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
"""Add the lock from the config."""
entry = hass.data[DOMAIN][config_entry.entry_id][COORDINATOR]

locks = [Lock(entry)]
async_add_entities(locks, False)
lock = Lock(entry)
if lock.coordinator.data.get("lockStatus", {}) and lock.coordinator.data["lockStatus"]["value"] != "ERROR":
async_add_entities([lock], False)
else:
_LOGGER.debug("Ford model doesn't support remote locking")


class Lock(FordPassEntity, LockEntity):
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 @@ -12,6 +12,6 @@
"loggers": ["custom_components.fordpass"],
"requirements": [],
"ssdp": [],
"version": "0.1.47",
"version": "0.1.48",
"zeroconf": []
}
7 changes: 6 additions & 1 deletion custom_components/fordpass/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def get_value(self, ftype):
if self.sensor == "odometer":
if self.fordoptions[CONF_DISTANCE_UNIT] != None:
if self.fordoptions[CONF_DISTANCE_UNIT] == "mi":
if self.fordoptions[DISTANCE_CONVERSION_DISABLED] == True:
if DISTANCE_CONVERSION_DISABLED in self.fordoptions and self.fordoptions[DISTANCE_CONVERSION_DISABLED] == True:
return self.coordinator.data[self.sensor]["value"]
else:
return round(
Expand Down Expand Up @@ -200,6 +200,11 @@ def get_value(self, ftype):
return None
elif self.sensor == "messages":
return "Messages"
elif self.sensor == "elVeh":
if self.fordoptions[CONF_DISTANCE_UNIT] == "mi":
return "mi"
else:
return "km"
elif self.sensor == "exhaustFluidLevel":
return "%"
elif ftype == "attribute":
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 @@ -18,7 +18,8 @@
"unknown": "[%key:common::config_flow::error::unknown%]"
},
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_account%]"
"already_configured": "[%key:common::config_flow::abort::already_configured_account%]",
"no_vehicles": "[%key:common::config_flow::abort::no_vehicles%]"
}
},
"options": {
Expand Down
2 changes: 2 additions & 0 deletions custom_components/fordpass/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ async def async_turn_on(self, **kwargs):
self.coordinator.vehicle.enableGuard
)
await self.coordinator.async_request_refresh()
self.async_write_ha_state()

async def async_turn_off(self, **kwargs):
if self.switch == "ignition":
Expand All @@ -61,6 +62,7 @@ async def async_turn_off(self, **kwargs):
self.coordinator.vehicle.disableGuard
)
await self.coordinator.async_request_refresh()
self.async_write_ha_state()

@property
def name(self):
Expand Down
29 changes: 27 additions & 2 deletions custom_components/fordpass/translations/en.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"config": {
"abort": {
"already_configured": "Account is already configured"
"already_configured": "Account is already configured",
"no_vehicles": "No vehicles on account or all are configured already"
},
"error": {
"cannot_connect": "Failed to connect",
"invalid_auth": "Invalid authentication",
"invalid_auth": "Invalid Credentials",
"invalid_vin": "Vin not found for given account",
"unknown": "Unexpected error"
},
Expand Down Expand Up @@ -33,5 +34,29 @@
}
}
},
"services": {
"refresh_status": {
"name": "Refresh Vehicle Status",
"description": "Poll car for latest status (Takes up to 5mins to update once this function has been run!)",
"fields": {
"vin": {
"name": "VIN",
"description": "Parse a vin number to only refresh the specified vehicle (Default refreshes all added vehicles)"
}
}
},
"clear_tokens": {
"name": "Clear Tokens",
"description": "Clear the token cache"
},
"reload": {
"name": "Reload",
"description": "Reload the Fordpass Integration"
},
"poll_api": {
"name": "Poll API",
"description": "Manually poll API for data update (Warning: doing this too often could result in a ban)"
}
},
"title": "Fordpass"
}
27 changes: 26 additions & 1 deletion custom_components/fordpass/translations/fr.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"config": {
"abort": {
"already_configured": "Le compte est déjà configuré"
"already_configured": "Le compte est déjà configuré",
"no_vehicles": "Aucun véhicule en compte ou tous sont déjà configurés"
},
"error": {
"cannot_connect": "Impossible de se connecter",
Expand Down Expand Up @@ -33,5 +34,29 @@
}
}
},
"services": {
"refresh_status": {
"name": "Actualiser l'état du véhicule",
"description": "Sonder la voiture pour le dernier statut (Prend jusqu'à 5 minutes pour mettre à jour une fois que cette fonction a été exécutée !)",
"fields": {
"vin": {
"name": "VIN",
"description": "Analyser un numéro vin pour actualiser uniquement le véhicule spécifié (la valeur par défaut actualise tous les véhicules ajoutés)"
}
}
},
"clear_tokens": {
"name": "Effacer les jetons",
"description": "Vider le cache des jetons"
},
"reload": {
"name": "Recharger",
"description": "Recharger l'intégration Fordpass"
},
"poll_api": {
"name": "API de sondage",
"description": "Interroger manuellement l'API pour la mise à jour des données (Attention : le faire trop souvent pourrait entraîner une interdiction)"
}
},
"title": "Fordpass"
}
27 changes: 26 additions & 1 deletion custom_components/fordpass/translations/nl.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"config": {
"abort": {
"already_configured": "Account is al geconfigureerd"
"already_configured": "Account is al geconfigureerd",
"no_vehicles": "Geen voertuigen op account of ze zijn allemaal al geconfigureerd"
},
"error": {
"cannot_connect": "Kan geen verbinding maken",
Expand Down Expand Up @@ -33,5 +34,29 @@
}
}
},
"services": {
"refresh_status": {
"name": "Voertuigstatus vernieuwen",
"description": "Poll auto voor de laatste status (duurt tot 5 minuten om te updaten zodra deze functie is uitgevoerd!)",
"fields": {
"vin": {
"name": "VIN",
"description": "Parseer een chassisnummer om alleen het opgegeven voertuig te vernieuwen (standaard vernieuwt alle toegevoegde voertuigen)"
}
}
},
"clear_tokens": {
"name": "Tokens wissen",
"description": "Wis de tokencache"
},
"reload": {
"name": "herladen",
"description": "Laad de Fordpass-integratie opnieuw"
},
"poll_api": {
"name": "Poll API",
"description": "API handmatig peilen voor gegevensupdate (Waarschuwing: als u dit te vaak doet, kan dit resulteren in een ban)"
}
},
"title": "FordPass"
}
5 changes: 5 additions & 0 deletions info.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
## **Changelog**
### Version 1.48
- Add translations for service strings
- Fix error on odometer missing config
- Handle unsupported car locks
- Add Units for elVeh DTE
### Version 1.47
- Add poll_api service to allow for manual refreshing of data outside of poll interval (e.g. poll more when driving)
- Add option to disable distance conversion when units displaying wrong in certain countries
Expand Down

0 comments on commit 5cb7a5e

Please sign in to comment.