Skip to content

Commit

Permalink
Merge pull request #403 from itchannel/1.61
Browse files Browse the repository at this point in the history
1.61
  • Loading branch information
itchannel committed Oct 31, 2023
2 parents 6861089 + d35c207 commit 8ef0987
Show file tree
Hide file tree
Showing 7 changed files with 940 additions and 569 deletions.
57 changes: 32 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,25 @@ A number of users have encountered their accounts being banned for containing "+
## **Changelog**
[Updates](info.md)

## 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:
## Installation
Use [HACS](https://hacs.xyz/) to add this repository as a custom repo. Upon installation navigate to your integrations, and follow the configuration options. You will need to provide:
- Username (Fordpass App)
- Password (Fordpass App)
- VIN Number (Not required in 1.50)
- Region (Where you are based, required for tokens to work correctly)

## Usage
## Requirement
Your car must have the lastest onboard modem functionality and have registered/authorised the fordpass application

### Car Refresh
I have added a service to poll the car for updates, due to the battery drain I have left this up to you to set the interval. The service to be called is "refresh_status" and can be accessed in home assistant using "fordpas.refresh_status".
## Services

### Car Refresh
I have added a service to poll the car for updates, due to the battery drain I have left this up to you to set the interval. The service to be called is "refresh_status" and can be accessed in home assistant using "fordpass.refresh_status".

Optionally you can add the "vin" parameter followed by your VIN number to only refresh one vehicle. By default this service will refresh all registered cars in HA.

**This will take up to 5 mins to update from the car once the service has been run**
###

### Unit Conversion
Click on options and choose imperial or metric to display in km/miles. Takes effect on next restart of home assistant. Default is Metric

### Clear Tokens
Expand All @@ -75,30 +77,35 @@ This service allows you to manually refresh/poll the API without waiting the set


## Currently Working
Depending on your vehicles capability

### Switches
- Guard Mode
- Lock/Unlock
- Remote Start

### Sensors
- Alarm Status
- Battery Status (12v)
- Coolant Temperature
- Deep sleep status
- Diesel System
- Door Status
- Electric Vehicle Support
- Firmware Update Status
- Fuel Level
- Ignition Status
- Indicators (Value of various vehicles indicators)
- Last Refresh
- FordPass messages and alerts
- Odometer
- Lock/Unlock
- Oil Status
- Last known GPS Coordinates/Map
- Outside Temperature
- Speed
- Tyre Status
- Battery Status
- Ignition Status
- Alarm Status
- Individual door statuses
- Remote Start
- Window Status (Only if your car supports it!)
- Last Car Refresh status
- Car Tracker
- Supports Multiple Regions
- Electric Vehicle Support
- TPMS Sensors
- Guard Mode (Only supported cars)
- Deep sleep status
- Fordpass messages and alerts


- Car Tracker
- Window Status

## Disclaimer

This integration is not officially supported by Ford and as such using this integration could result in your account being locked out!
92 changes: 88 additions & 4 deletions custom_components/fordpass/autonomicData.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@
import requests


# Place this script in the /config/custom_components/fordpass folder on your HomeAssistant
# Add the details below
# run from a terminal in the /config/custom_components/fordpass folder: python3 autonomicData.py
# From a terminal in the /config/custom_components/fordpass folder run: python3 autonomicData.py
# Script will automatically redact your VIN, VehicleID, and Geolocation details (lat, long) by default, but can be turned off

# USER INPUT DATA

# Required: Enter the VIN to query
FP_VIN = ""

# Required: Your region. Uncomment your region if it is different, then comment out the other one (# is a comment).

#REGION = "UK&Europe"
#REGION = "Australia"
REGION = "North America & Canada"

# Automatically redact json? (True or False) False is only recommended if you would like to save your json for personal use
REDACTION = True

Expand All @@ -31,6 +36,16 @@
VERBOSE = True






region_lookup = {
"UK&Europe": "1E8C7794-FF5F-49BC-9596-A1E0C86C5B19",
"Australia": "5C80A6BB-CF0D-4A30-BDBF-FC804B5C1A98",
"North America & Canada": "71A3AD0A-CF46-4CCF-B473-FC7FE5BC4592",
}

def get_autonomic_token(ford_access_token):
"""Get Autonomic API token from FordPass token"""
url = "https://accounts.autonomic.ai/v1/auth/oidc/token"
Expand Down Expand Up @@ -127,6 +142,65 @@ def redact_json(data, redaction):
redact_json(item, redaction)


def vehicle_cap(access_token, region):
"""Make call to vehicles API"""
regionID = region_lookup[region]
if region == "Australia":
countryheader = "AUS"
elif region == "North America & Canada":
countryheader = "USA"
elif region == "UK&Europe":
countryheader = "GBR"
else:
countryheader = "USA"

headers = {
"Accept": "*/*",
"Accept-Language": "en-us",
"User-Agent": "FordPass/23 CFNetwork/1408.0.4 Darwin/22.5.0",
"Accept-Encoding": "gzip, deflate, br",
"Content-Type": "application/json",
"Auth-Token": access_token,
"Application-Id": regionID,
"Countrycode": countryheader,
"Locale": "EN-US"
}

data = {
"dashboardRefreshRequest": "All"
}

redaction_items = ["VIN", "vin", "vehicleImage"]

try:
response = requests.post(
f"https://api.mps.ford.com/api/expdashboard/v1/details/",
headers=headers,
data=json.dumps(data)
)
response.raise_for_status()
print("Got vehicle capabilities")
vehicleCap = response.json()
if REDACTION:
redact_json(vehicleCap, redaction_items)
return vehicleCap

except requests.exceptions.HTTPError as errh:
print(f"HTTP Error: {errh}")
# print("Trying refresh token")
# get_autonomic_token(fp_refresh)
return None
except requests.exceptions.ConnectionError as errc:
print(f"Error Connecting: {errc}")
sys.exit()
except requests.exceptions.Timeout as errt:
print(f"Timeout Error: {errt}")
sys.exit()
except requests.exceptions.RequestException as err:
print(f"Something went wrong: {err}")
sys.exit()


if __name__ == "__main__":
FORD_PASS_DIR = "/config/custom_components/fordpass"
existingfordToken = os.path.join(FORD_PASS_DIR, "*_fordpass_token.txt")
Expand Down Expand Up @@ -158,7 +232,10 @@ def redact_json(data, redaction):
print("WARNING: json will contain sensitive information!")
# Exchange Fordpass token for Autonomic Token
autonomic_token = get_autonomic_token(fpToken)
# Get vehicle status
vehicle_status = get_vehicle_status(FP_VIN, autonomic_token["access_token"])
# Get vehicle capabilities
vehicle_capability = vehicle_cap(fpToken, REGION)
current_datetime = datetime.now().strftime("%Y-%m-%d_%H:%M:%S")
if VIC_YEAR != "":
VIC_YEAR = VIC_YEAR.replace(" ", "_") + "-"
Expand All @@ -169,9 +246,16 @@ def redact_json(data, redaction):

fileName = os.path.join(FORD_PASS_DIR, f"{VIC_YEAR}{VIC_MODEL}_status_{current_datetime}{REDACTION_STATUS}.json")

if vehicle_capability != None:
vehicleData = [vehicle_status, vehicle_capability]
else:
if VERBOSE:
print("Unable to get vehicle capability, saving vehicle status")
vehicleData = vehicle_status

# Write the redacted JSON data to the file
with open(fileName, 'w', encoding="utf-8") as file:
json.dump(vehicle_status, file, indent=4)
json.dump(vehicleData, file, indent=4)
if VERBOSE:
print(f"File saved: {fileName}")
print("Note: json file will be deleted if fordpass-ha is updated")
print("Note: json file will be deleted if fordpass-ha is updated")
Loading

0 comments on commit 8ef0987

Please sign in to comment.