Skip to content

Commit

Permalink
Merge pull request #343 from itchannel/1.57
Browse files Browse the repository at this point in the history
1.57
  • Loading branch information
itchannel committed Oct 13, 2023
2 parents e14cba6 + 6141e34 commit a3ea0dd
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
33 changes: 31 additions & 2 deletions custom_components/fordpass/fordpass_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ def __poll_status(self, url, command_id):

def __request_and_poll_command(self, command, vin=None):
"""Send command to the new Command endpoint"""
self.__acquire_token()
headers = {
**apiHeaders,
"Application-Id": self.region,
Expand Down Expand Up @@ -592,8 +593,36 @@ def __request_and_poll_command(self, command, vin=None):
_LOGGER.debug(r.status_code)
_LOGGER.debug(r.text)
if r.status_code == 201:
time.sleep(90)
return True
# New code to hanble checking states table from vehicle data
response = r.json()
command_id = response["id"]
current_status = response["currentStatus"]
i = 1
while i < 14:
# Check status every 10 seconds for 90 seconds until command completes or time expires
status = self.status()
_LOGGER.debug("STATUS")
_LOGGER.debug(status)

if "states" in status:
_LOGGER.debug("States located")
if f"{command}Command" in status["states"]:
_LOGGER.debug("Found command")
_LOGGER.debug(status["states"][f"{command}Command"]["commandId"])
if status["states"][f"{command}Command"]["commandId"] == command_id:
_LOGGER.debug("Making progress")
_LOGGER.debug(status["states"][f"{command}Command"])
if status["states"][f"{command}Command"]["value"]["toState"] == "success":
_LOGGER.debug("Command succeeded")
return True
if status["states"][f"{command}Command"]["value"]["toState"] == "expired":
_LOGGER.debug("Command expired")
return False
i += 1
_LOGGER.debug("Looping again")
time.sleep(10)
#time.sleep(90)
return False
return False

def __request_and_poll(self, method, url):
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.56",
"version": "0.1.57",
"zeroconf": []
}
1 change: 1 addition & 0 deletions custom_components/fordpass/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ def get_value(self, ftype):
)
else:
elecs["Maximum Battery Range"] = self.data["xevBatteryMaximumRange"]["value"]
return elecs

## SquidBytes: Added elVehCharging
if self.sensor == "elVehCharging":
Expand Down
4 changes: 4 additions & 0 deletions info.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## **Changelog**
### Version 1.57
- Rewrote command function to actively poll until success or failure is returned
- Fixed bug where elveh attributes wasn't showing
- Fixed bug where command wouldn't check token expiry first
### Version 1.56
- Fix for error when missing GPS data from vehicle
- Fix for electric vehicle error
Expand Down

0 comments on commit a3ea0dd

Please sign in to comment.