Skip to content

Commit

Permalink
Merge branch '1.70' of github.com:itchannel/fordpass-ha into 1.70
Browse files Browse the repository at this point in the history
  • Loading branch information
SquidBytes committed Jan 19, 2025
2 parents fb62c82 + 43d06dd commit 93ceb80
Show file tree
Hide file tree
Showing 15 changed files with 356 additions and 281 deletions.
96 changes: 45 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,42 @@

[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/itchannel)

<!-- Wrote up a little note thing for the breaking change. Not sure if you want to use it but I figured this could be a good start or something since I was already editing the readme. -->
> [!WARNING]
> Due to what looks like a Ford API change the integration isn't currently working as of 08/05/2024. I recommend disabling it for the time being until we can take a look at what has changed.
> # Breaking Change
> There is a new token obtaining system.
>
> The token used by this integration is currently removed whenever the integration is updated. With this 1.70 update, the token will be wiped during every update, requiring users to manually add the token during the initial setup.
>
> To prevent this issue, we will be moving the token file outside of the FordPass directory. This change will ensure that the token is preserved during updates. This will require reconfiguration of your setup.
> Please see the Installation section, or the Wiki for help.
<!-- Tried to update the update with the new information -->
> [!IMPORTANT]
> # FordConnect API
>
> For anyone who wants to try there is a version 1.70 which works but is more fiddly to setup. Please see https://github.com/itchannel/fordpass-ha/wiki/Obtaining-Tokens-(As-of-25-05-2024) for instructions
> Dear FordPass Integration Users,
> As you know there have been many challenges with the Ford API. We > are actively working on developments but please note that these developments **will take time.**
> - **FordConnect API:** Ford has enabled developer accounts and released their `FordConnect API`. However, this API and its documentation currently **lack many data points** or **are not fully >implemented**. It is presently supported only in North America.
> - **FordPass APP:** Ford has also released their refreshed `FordPass App`. This refreshed app includes some new features while also >removing certain items, similar to the FordConnect API.
>
> It is important to understand that our integration depends on the data provided by either the `FordConnect API` or the `FordPass App`, >which may limit some functionalities.
## Future Updates:

# Important Update: New Ford API Challenges and Updates
- **Enhancements:** We are committed to enhancing the integration and ensuring its functionality. However, we both have limited time to allocate to this effort.

Dear FordPass Integration Users,
- **Implementation:** We are actively working on integrating the new `FordConnect API` to ensure users who can access it will benefit from its features. At the same time, we will maintain functionality for users who are unable to use this new API.

We want to keep you informed about the latest developments regarding the integration. Ford has recently introduced a new API, which has presented both opportunities and challenges. Here are some key points to note:

## Challenges and Issues:

- **Increased Complexity:** The new API has brought about several challenges and complexities. While it has enabled new attributes and sensors for different vehicles, it has also made integration more intricate.

- **Vehicle Variety:** In addition to an entirely new data structure, it is difficult to determine the variety of vehicles that can be supported - without knowing their capabilities. We are assessing which vehicles contain the information necessary to enable different sensors.

- **Unstable Nature of the New API:** Currently, the API appears to be unstable and/or changing. Any changes to its structure can disrupt sensor data. It is difficult to determine why: vehicles may still be in the process of migration, needing an update, or have a different data structure. Either way, instability has been noticed, and any updates or changes to the API can impact this integration.

## Ongoing Work and Future Updates:

- **Ongoing Work:** We both want to continue enhancing the integration and ensuring its functionality. However, it's important to note that we have limited time to allocate to this effort.

- **Future Updates:** We are continuing our efforts to adapt to new changes and persue further enhancments.


#### Please understand that there may be issues, or disruptions, to different sensors during this process.
#### Please be aware that there may be issues or disruptions during this process.

If you have any questions or concerns, please either open a new issue or comment on an existing issue related to yours.

Thank you,

itchannel and SquidBytes


## Credit
- https://github.com/clarkd - Initial Home Assistant automation idea and Python code (Lock/Unlock)
- https://github.com/pinballnewf - Figuring out the application ID issue
Expand All @@ -48,57 +49,49 @@ itchannel and SquidBytes
- https://github.com/heehoo59 - French Translation
- https://github.com/SquidBytes - EV updates and documentation

## Account Warning (Sep 2023)
A number of users have encountered their accounts being banned for containing "+" symbols in their email. It appears Ford thinks this is a disposable email. So if you have a + in your email I recommend changing it.

## **Changelog**
[Updates](info.md)

## 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)
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:
- Fordpass Email
- Region (Where you are based, required for tokens to work correctly)

## Requirement
You will then be prompted with `Setup Token`

Follow the instructions on the [Wiki](https://github.com/itchannel/fordpass-ha/wiki/Obtaining-Tokens-(As-of-25-05-2024)) to obtain your token

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

## 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".
## Services
<!-- I haven't looked into these services, but it might be easier to maintain a Wiki with the various services compared to the README. Just a thought. -->
### 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".

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

<!-- These might need to be updated since its now different -->
### Clear Tokens
If you are experiencing any sign in issues, please trying clearing your tokens using the "clear_tokens" service call.

### Poll API
This service allows you to manually refresh/poll the API without waiting the set poll interval. Handy if you need quicker updates e.g. when driving for gps coordinates


## Currently Working
Depending on your vehicles capability

### Switches
- Guard Mode
- Lock/Unlock
- Remote Start
## Sensors
### Currently Working
**Sensors may change as the integration is being developed**
<!-- Keeping this the same, but it will probably change and update alongside Fordconnect and the new app features -->

### 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)
Expand All @@ -110,8 +103,9 @@ Depending on your vehicles capability
- Speed
- Tyre Status
- TPMS Sensors
- Car Tracker
- Window Status
- Guard Mode (Only supported cars)
- Deep sleep status
- Fordpass messages and alerts

## Disclaimer
This integration is not officially supported by Ford and as such using this integration could result in your account being locked out!
8 changes: 3 additions & 5 deletions custom_components/fordpass/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
CONF_PRESSURE_UNIT,
DEFAULT_DISTANCE_UNIT,
DEFAULT_PRESSURE_UNIT,
DEFAULT_REGION,
DOMAIN,
MANUFACTURER,
REGION,
Expand Down Expand Up @@ -61,7 +62,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
region = entry.data[REGION]
else:
_LOGGER.debug("CANT GET REGION")
region = "North America & Canada"
region = DEFAULT_REGION
coordinator = FordPassDataUpdateCoordinator(hass, user, password, vin, region, update_interval, 1)

await coordinator.async_refresh() # Get initial data
Expand All @@ -79,10 +80,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
"fordpass_options_listener": fordpass_options_listener
}

for component in PLATFORMS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, component)
)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

async def async_refresh_status_service(service_call):
await hass.async_add_executor_job(
Expand Down
94 changes: 8 additions & 86 deletions custom_components/fordpass/autonomicData.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,18 @@
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
redaction = True

# Optional: Enter your vehicle year (example: 2023)
VIC_YEAR = ""

# Optional: Enter your vehicle model (example: Lightning)
VIC_MODEL = ""
vicModel = ""

# You can turn off print statements if you want to use this script for other purposes (True or False)
VERBOSE = True
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 All @@ -69,9 +59,8 @@ def get_autonomic_token(ford_access_token):

except requests.exceptions.HTTPError as errh:
print(f"HTTP Error: {errh}")
# print("Trying refresh token")
# get_autonomic_token(fp_refresh)
return None
print("Trying refresh token")
get_autonomic_token(fpRefresh)
except requests.exceptions.ConnectionError as errc:
print(f"Error Connecting: {errc}")
sys.exit()
Expand Down Expand Up @@ -115,7 +104,6 @@ def get_vehicle_status(vin, access_token):
print(f"Timeout Error: {errt}")
except requests.exceptions.RequestException as err:
print(f"Something went wrong: {err}")
return None


def redact_json(data, redaction):
Expand All @@ -142,65 +130,6 @@ 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 @@ -242,20 +171,13 @@ def vehicle_cap(access_token, region):
if VIC_MODEL != "":
VIC_MODEL = VIC_MODEL.replace(" ", "_")
else:
VIC_MODEL = "my"

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

if vehicle_capability != None:
vehicleData = [vehicle_status, vehicle_capability]
else:
if VERBOSE:
print("Unable to get vehicle capability, saving vehicle status")
vehicleData = vehicle_status
fileName = os.path.join(fordPassDir, f"{vicYear}{vicModel}_status_{current_datetime}{redactionStatus}.json")

# Write the redacted JSON data to the file
with open(fileName, 'w', encoding="utf-8") as file:
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 93ceb80

Please sign in to comment.