From cb10c911a417eebf40b6c6d929b2b6a6354f7a25 Mon Sep 17 00:00:00 2001 From: steve Date: Fri, 13 Oct 2023 21:37:28 +1000 Subject: [PATCH 1/3] command now polls status --- custom_components/fordpass/fordpass_new.py | 32 ++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/custom_components/fordpass/fordpass_new.py b/custom_components/fordpass/fordpass_new.py index 538f0c9..22f2940 100644 --- a/custom_components/fordpass/fordpass_new.py +++ b/custom_components/fordpass/fordpass_new.py @@ -592,8 +592,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 < 9: + # 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): From e4604549bf223c1b48caa248c81869ca67c753b0 Mon Sep 17 00:00:00 2001 From: steve Date: Fri, 13 Oct 2023 22:02:25 +1000 Subject: [PATCH 2/3] Missing elveh attributes + refresh bug --- custom_components/fordpass/fordpass_new.py | 1 + custom_components/fordpass/sensor.py | 1 + 2 files changed, 2 insertions(+) diff --git a/custom_components/fordpass/fordpass_new.py b/custom_components/fordpass/fordpass_new.py index 22f2940..e383c58 100644 --- a/custom_components/fordpass/fordpass_new.py +++ b/custom_components/fordpass/fordpass_new.py @@ -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, diff --git a/custom_components/fordpass/sensor.py b/custom_components/fordpass/sensor.py index 439e338..5176602 100644 --- a/custom_components/fordpass/sensor.py +++ b/custom_components/fordpass/sensor.py @@ -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": From 6141e342ce85bb949b5198170867605c7507649f Mon Sep 17 00:00:00 2001 From: steve Date: Fri, 13 Oct 2023 22:05:37 +1000 Subject: [PATCH 3/3] updated info.md --- custom_components/fordpass/fordpass_new.py | 2 +- custom_components/fordpass/manifest.json | 2 +- info.md | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/custom_components/fordpass/fordpass_new.py b/custom_components/fordpass/fordpass_new.py index e383c58..bdfdf6b 100644 --- a/custom_components/fordpass/fordpass_new.py +++ b/custom_components/fordpass/fordpass_new.py @@ -598,7 +598,7 @@ def __request_and_poll_command(self, command, vin=None): command_id = response["id"] current_status = response["currentStatus"] i = 1 - while i < 9: + while i < 14: # Check status every 10 seconds for 90 seconds until command completes or time expires status = self.status() _LOGGER.debug("STATUS") diff --git a/custom_components/fordpass/manifest.json b/custom_components/fordpass/manifest.json index 755de44..cbbf2d2 100644 --- a/custom_components/fordpass/manifest.json +++ b/custom_components/fordpass/manifest.json @@ -12,6 +12,6 @@ "loggers": ["custom_components.fordpass"], "requirements": [], "ssdp": [], - "version": "0.1.56", + "version": "0.1.57", "zeroconf": [] } \ No newline at end of file diff --git a/info.md b/info.md index ffb4025..4a3907f 100644 --- a/info.md +++ b/info.md @@ -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