Skip to content

Commit

Permalink
Merge branch 'Region-Beta' of github.com:itchannel/fordpass-ha into R…
Browse files Browse the repository at this point in the history
…egion-Beta
  • Loading branch information
itchannel committed Nov 28, 2020
2 parents aa811ad + dfbe37d commit 9bc0d92
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 24 deletions.
4 changes: 1 addition & 3 deletions custom_components/fordpass/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
UpdateFailed,
)

from .const import CONF_UNIT, DEFAULT_UNIT, DOMAIN, MANUFACTURER, VEHICLE, VIN, REGION
from .const import CONF_UNIT, DEFAULT_UNIT, DOMAIN, MANUFACTURER, REGION, VEHICLE, VIN
from .fordpass_new import Vehicle

CONFIG_SCHEMA = vol.Schema({DOMAIN: vol.Schema({})}, extra=vol.ALLOW_EXTRA)
Expand All @@ -28,8 +28,6 @@
SCAN_INTERVAL = timedelta(seconds=300)




async def async_setup(hass: HomeAssistant, config: dict):
"""Set up the FordPass component."""
hass.data.setdefault(DOMAIN, {})
Expand Down
6 changes: 3 additions & 3 deletions custom_components/fordpass/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
CONF_UNITS,
DEFAULT_UNIT,
DOMAIN,
VIN,
REGION,
REGION_OPTIONS
REGION_OPTIONS,
VIN,
)
from .fordpass_new import Vehicle

Expand All @@ -24,7 +24,7 @@
vol.Required(CONF_USERNAME): str,
vol.Required(CONF_PASSWORD): str,
vol.Required(VIN): vol.All(str, vol.Length(min=17, max=17)),
vol.Required(REGION): vol.In(REGION_OPTIONS)
vol.Required(REGION): vol.In(REGION_OPTIONS),
}
)

Expand Down
7 changes: 1 addition & 6 deletions custom_components/fordpass/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,4 @@

REGION = "region"

REGION_OPTIONS = [
"UK&Europe",
"Australia",
"North America & Canada"
]

REGION_OPTIONS = ["UK&Europe", "Australia", "North America & Canada"]
18 changes: 6 additions & 12 deletions custom_components/fordpass/fordpass_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
region_lookup = {
"UK&Europe": "1E8C7794-FF5F-49BC-9596-A1E0C86C5B19",
"Australia": "5C80A6BB-CF0D-4A30-BDBF-FC804B5C1A98",
"North America & Canada": "71A3AD0A-CF46-4CCF-B473-FC7FE5BC4592"
"North America & Canada": "71A3AD0A-CF46-4CCF-B473-FC7FE5BC4592",
}

baseUrl = "https://usapi.cv.ford.com/api"
Expand Down Expand Up @@ -65,10 +65,7 @@ def auth(self):
logging.info("Succesfully fetched token Stage1")
result = r.json()
data = {"code": result["access_token"]}
headers = {
**apiHeaders,
"Application-Id": self.region
}
headers = {**apiHeaders, "Application-Id": self.region}
# Fetch OAUTH token stage 2 and refresh token
r = requests.put(
"https://api.mps.ford.com/api/oauth2/v1/token",
Expand All @@ -90,10 +87,7 @@ def auth(self):
def refreshToken(self, token):
# Token is invalid so let's try refreshing it
data = {"refresh_token": token["refresh_token"]}
headers = {
**apiHeaders,
"Application-Id": self.region
}
headers = {**apiHeaders, "Application-Id": self.region}

r = requests.put(
"https://api.mps.ford.com/api/oauth2/v1/refresh",
Expand Down Expand Up @@ -158,10 +152,10 @@ def status(self):
params = {"lrdt": "01-01-1970 00:00:00"}

headers = {
**apiHeaders,
**apiHeaders,
"auth-token": self.token,
"Application-Id": self.region
}
"Application-Id": self.region,
}

r = requests.get(
f"{baseUrl}/vehicles/v4/{self.vin}/status", params=params, headers=headers
Expand Down

0 comments on commit 9bc0d92

Please sign in to comment.