From fb55f6122c549ab24fb2665516a8f699216721aa Mon Sep 17 00:00:00 2001 From: steve Date: Tue, 18 Jul 2023 10:51:39 +1000 Subject: [PATCH 01/10] Add service to poll API manually --- custom_components/fordpass/__init__.py | 9 +++++++++ custom_components/fordpass/manifest.json | 14 +++++++------- custom_components/fordpass/services.yaml | 3 +++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/custom_components/fordpass/__init__.py b/custom_components/fordpass/__init__.py index b3e0670..1603da3 100644 --- a/custom_components/fordpass/__init__.py +++ b/custom_components/fordpass/__init__.py @@ -93,6 +93,9 @@ async def async_refresh_status_service(service_call): async def async_clear_tokens_service(service_call): await hass.async_add_executor_job(clear_tokens, hass, service_call, coordinator) + async def poll_api_service(service_call): + await coordinator.async_request_refresh() + async def handle_reload(service): """Handle reload service call.""" @@ -123,6 +126,12 @@ async def handle_reload(service): handle_reload ) + hass.services.async_register( + DOMAIN, + "poll_api", + poll_api_service + ) + return True diff --git a/custom_components/fordpass/manifest.json b/custom_components/fordpass/manifest.json index 4760f9e..fffb648 100644 --- a/custom_components/fordpass/manifest.json +++ b/custom_components/fordpass/manifest.json @@ -1,16 +1,16 @@ { "domain": "fordpass", "name": "FordPass", + "codeowners": ["@itchannel"], "config_flow": true, - "integration_type": "device", + "dependencies": [], "documentation": "https://github.com/itchannel/fordpass-ha", + "homekit": {}, + "integration_type": "device", + "iot_class": "cloud_polling", "issue_tracker": "https://github.com/itchannel/fordpass-ha/issues", - "version": "0.1.46", "requirements": [], "ssdp": [], - "zeroconf": [], - "homekit": {}, - "dependencies": [], - "iot_class": "cloud_polling", - "codeowners": ["@itchannel"] + "version": "0.1.47", + "zeroconf": [] } \ No newline at end of file diff --git a/custom_components/fordpass/services.yaml b/custom_components/fordpass/services.yaml index bda85d5..a8b22ce 100644 --- a/custom_components/fordpass/services.yaml +++ b/custom_components/fordpass/services.yaml @@ -12,3 +12,6 @@ clear_tokens: reload: name: Reload description: "Reload the Fordpass Integration" +poll_api: + name: Poll API + description: "Manually poll API for data update (Warning: doing this too often could result in a ban)" \ No newline at end of file From a5e9e2613a75d67279c688f1a3784b42e7870605 Mon Sep 17 00:00:00 2001 From: steve Date: Tue, 18 Jul 2023 11:21:53 +1000 Subject: [PATCH 02/10] Add ability to disable mileage conversion in optio --- custom_components/fordpass/config_flow.py | 10 +++++++++- custom_components/fordpass/const.py | 2 ++ custom_components/fordpass/sensor.py | 12 ++++++++---- custom_components/fordpass/strings.json | 1 + custom_components/fordpass/translations/en.json | 1 + custom_components/fordpass/translations/fr.json | 1 + custom_components/fordpass/translations/nl.json | 1 + 7 files changed, 23 insertions(+), 5 deletions(-) diff --git a/custom_components/fordpass/config_flow.py b/custom_components/fordpass/config_flow.py index 8980845..66d6292 100644 --- a/custom_components/fordpass/config_flow.py +++ b/custom_components/fordpass/config_flow.py @@ -18,7 +18,9 @@ REGION_OPTIONS, VIN, UPDATE_INTERVAL, - UPDATE_INTERVAL_DEFAULT + UPDATE_INTERVAL_DEFAULT, + DISTANCE_CONVERSION_DISABLED, + DISTANCE_CONVERSION_DISABLED_DEFAULT ) from .fordpass_new import Vehicle @@ -120,6 +122,12 @@ async def async_step_init(self, user_input=None): CONF_DISTANCE_UNIT, DEFAULT_DISTANCE_UNIT ), ): vol.In(DISTANCE_UNITS), + vol.Optional( + DISTANCE_CONVERSION_DISABLED, + default = self.config_entry.options.get( + DISTANCE_CONVERSION_DISABLED, DISTANCE_CONVERSION_DISABLED_DEFAULT + ), + ): bool, vol.Optional( UPDATE_INTERVAL, default=self.config_entry.options.get( diff --git a/custom_components/fordpass/const.py b/custom_components/fordpass/const.py index b6b8c07..2fb8027 100644 --- a/custom_components/fordpass/const.py +++ b/custom_components/fordpass/const.py @@ -16,6 +16,8 @@ PRESSURE_UNITS = ["PSI", "kPa", "BAR"] DISTANCE_UNITS = ["mi", "km"] +DISTANCE_CONVERSION_DISABLED = "distance_conversion" +DISTANCE_CONVERSION_DISABLED_DEFAULT = False UPDATE_INTERVAL = "update_interval" UPDATE_INTERVAL_DEFAULT = 900 diff --git a/custom_components/fordpass/sensor.py b/custom_components/fordpass/sensor.py index 7b145f7..9a929b2 100644 --- a/custom_components/fordpass/sensor.py +++ b/custom_components/fordpass/sensor.py @@ -11,7 +11,7 @@ ) from . import FordPassEntity -from .const import CONF_DISTANCE_UNIT, CONF_PRESSURE_UNIT, DOMAIN, SENSORS, COORDINATOR +from .const import CONF_DISTANCE_UNIT, CONF_PRESSURE_UNIT, DOMAIN, SENSORS, COORDINATOR, DISTANCE_CONVERSION_DISABLED _LOGGER = logging.getLogger(__name__) @@ -61,9 +61,13 @@ def get_value(self, ftype): if self.sensor == "odometer": if self.fordoptions[CONF_DISTANCE_UNIT] != None: if self.fordoptions[CONF_DISTANCE_UNIT] == "mi": - return round( - float(self.coordinator.data[self.sensor]["value"]) / 1.60934 - ) + if self.fordoptions[DISTANCE_CONVERSION_DISABLED] == True: + return self.coordinator.data[self.sensor]["value"] + else: + return round( + float(self.coordinator.data[self.sensor]["value"]) / 1.60934 + ) + else: return self.coordinator.data[self.sensor]["value"] else: diff --git a/custom_components/fordpass/strings.json b/custom_components/fordpass/strings.json index 5a15a63..c2a11e7 100644 --- a/custom_components/fordpass/strings.json +++ b/custom_components/fordpass/strings.json @@ -27,6 +27,7 @@ "data": { "pressure_unit": "Unit of Pressure", "distance_unit": "Unit of Distance", + "distance_conversion": "Disable distance conversion", "update_interval": "Interval to poll Fordpass API (Seconds)" }, "description": "Configure fordpass options" diff --git a/custom_components/fordpass/translations/en.json b/custom_components/fordpass/translations/en.json index cd746ad..72b540c 100644 --- a/custom_components/fordpass/translations/en.json +++ b/custom_components/fordpass/translations/en.json @@ -26,6 +26,7 @@ "data": { "pressure_unit": "Unit of Pressure", "distance_unit": "Unit of Distance", + "distance_conversion": "Disable distance conversion", "update_interval": "Interval to poll Fordpass API (Seconds)" }, "description": "Configure fordpass options" diff --git a/custom_components/fordpass/translations/fr.json b/custom_components/fordpass/translations/fr.json index 459bbd0..0499962 100644 --- a/custom_components/fordpass/translations/fr.json +++ b/custom_components/fordpass/translations/fr.json @@ -26,6 +26,7 @@ "data": { "pressure_unit": "Unité de pression", "distance_unit": "Unité de distance", + "distance_conversion": "Désactiver la conversion de distance", "update_interval": "Intervalle pour interroger l'API Fordpass (secondes)" }, "description": "Configuration de Fordpass" diff --git a/custom_components/fordpass/translations/nl.json b/custom_components/fordpass/translations/nl.json index 3042dae..ae17728 100644 --- a/custom_components/fordpass/translations/nl.json +++ b/custom_components/fordpass/translations/nl.json @@ -26,6 +26,7 @@ "data": { "pressure_unit": "Eenheid voor luchtdruk", "distance_unit": "Eenheid voor afstand", + "distance_conversion": "Deaktiver avstandskonvertering", "update_interval": "Interval om Fordpass API te peilen (seconden)" }, "description": "Instellingen FordPass" From 1524ec44088ebb7f20b29cd7cf12347bc3c16226 Mon Sep 17 00:00:00 2001 From: steve Date: Tue, 18 Jul 2023 11:42:17 +1000 Subject: [PATCH 03/10] add device class to last_refresh --- custom_components/fordpass/const.py | 2 +- custom_components/fordpass/sensor.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/custom_components/fordpass/const.py b/custom_components/fordpass/const.py index 2fb8027..b8ae300 100644 --- a/custom_components/fordpass/const.py +++ b/custom_components/fordpass/const.py @@ -40,7 +40,7 @@ "ignitionStatus": {"icon": "hass:power"}, "doorStatus": {"icon": "mdi:car-door"}, "windowPosition": {"icon": "mdi:car-door"}, - "lastRefresh": {"icon": "mdi:clock"}, + "lastRefresh": {"icon": "mdi:clock", "device_class": "timestamp"}, "elVeh": {"icon": "mdi:ev-station"}, "deepSleepInProgress": { "icon": "mdi:power-sleep", diff --git a/custom_components/fordpass/sensor.py b/custom_components/fordpass/sensor.py index 9a929b2..d070d37 100644 --- a/custom_components/fordpass/sensor.py +++ b/custom_components/fordpass/sensor.py @@ -461,5 +461,6 @@ def device_class(self): if "device_class" in SENSORS[self.sensor]: if SENSORS[self.sensor]["device_class"] == "distance": return SensorDeviceClass.DISTANCE - else: - return None + if SENSORS[self.sensor]["device_class"] == "timestamp": + return SensorDeviceClass.TIMESTAMP + return None From 07f99214e2338dc62aba39b7a11c2ab6a9b17f74 Mon Sep 17 00:00:00 2001 From: steve Date: Tue, 18 Jul 2023 11:44:20 +1000 Subject: [PATCH 04/10] update info.md --- info.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/info.md b/info.md index fb06c86..f981b50 100644 --- a/info.md +++ b/info.md @@ -1,4 +1,8 @@ ## **Changelog** +### Version 1.47 +- Add poll_api service to allow for manual refreshing of data outside of poll interval (e.g. poll more when driving) +- Add option to disable distance conversion when units displaying wrong in certain countries +- Add device_class to "last_refresh" sensor ### Version 1.46 - Fix diesel filter error ### Version 1.45 From 5cabc287acc66c09529fb8aa2ac3345017d23f96 Mon Sep 17 00:00:00 2001 From: steve Date: Tue, 18 Jul 2023 11:46:42 +1000 Subject: [PATCH 05/10] updated README --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 506e560..f4ced0b 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,9 @@ - https://github.com/JacobWasFramed - Updated unit conversions - https://github.com/heehoo59 - French Translation -## 1.23 Breaking Change -The way the units work has been changed so if updating please go to "Integrations" and click options on fordpass and choose your preferred units (miles/km etc) and restart HA. Not doing this will result in an error!! +## 1.47 Change +If you are experiencing issues with the odometer displaying wrong, please try enabling the checkbox in options for "Disable Distance Conversion" + ## 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: @@ -37,6 +38,8 @@ Click on options and choose imperial or metric to display in km/miles. Takes eff ### 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 @@ -63,9 +66,6 @@ If you are experiencing any sign in issues, please trying clearing your tokens u - Fordpass messages and alerts -## Coming Soon - -- Next service due ## Disclaimer From 89b54769c5f53fe6b994c5f4fadd6cef87f8d03f Mon Sep 17 00:00:00 2001 From: steve Date: Tue, 18 Jul 2023 12:09:27 +1000 Subject: [PATCH 06/10] Add locking/unlocking status to lock entity --- custom_components/fordpass/lock.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/custom_components/fordpass/lock.py b/custom_components/fordpass/lock.py index d852ef5..dde641e 100644 --- a/custom_components/fordpass/lock.py +++ b/custom_components/fordpass/lock.py @@ -30,19 +30,27 @@ def __init__(self, coordinator): async def async_lock(self, **kwargs): """Locks the vehicle.""" + self._attr_is_locking = True + self.async_write_ha_state() _LOGGER.debug("Locking %s", self.coordinator.vin) await self.coordinator.hass.async_add_executor_job( self.coordinator.vehicle.lock ) await self.coordinator.async_request_refresh() + self._attr_is_locking = False + self.async_write_ha_state() async def async_unlock(self, **kwargs): """Unlocks the vehicle.""" + self._attr_is_unlocking = True + self.async_write_ha_state() _LOGGER.debug("Unlocking %s", self.coordinator.vin) await self.coordinator.hass.async_add_executor_job( self.coordinator.vehicle.unlock ) await self.coordinator.async_request_refresh() + self._attr_is_unlocking = False + self.async_write_ha_state() @property def is_locked(self): From f904ed0f0ba7759b281f557f0c88e55c18ad5bb7 Mon Sep 17 00:00:00 2001 From: steve Date: Tue, 18 Jul 2023 12:23:19 +1000 Subject: [PATCH 07/10] update info.md --- info.md | 1 + 1 file changed, 1 insertion(+) diff --git a/info.md b/info.md index f981b50..796e3be 100644 --- a/info.md +++ b/info.md @@ -3,6 +3,7 @@ - Add poll_api service to allow for manual refreshing of data outside of poll interval (e.g. poll more when driving) - Add option to disable distance conversion when units displaying wrong in certain countries - Add device_class to "last_refresh" sensor +- Add Locking/Unlocking status to lock entity ### Version 1.46 - Fix diesel filter error ### Version 1.45 From c972006a207234cf27fa4270330b499572c82667 Mon Sep 17 00:00:00 2001 From: steve Date: Tue, 18 Jul 2023 12:26:47 +1000 Subject: [PATCH 08/10] Updated to v5 endpoint + useragent --- custom_components/fordpass/fordpass_new.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/fordpass/fordpass_new.py b/custom_components/fordpass/fordpass_new.py index 848a603..3dad02e 100644 --- a/custom_components/fordpass/fordpass_new.py +++ b/custom_components/fordpass/fordpass_new.py @@ -16,7 +16,7 @@ defaultHeaders = { "Accept": "*/*", "Accept-Language": "en-us", - "User-Agent": "FordPass/5 CFNetwork/1197 Darwin/20.0.0", + "User-Agent": "FordPass/23 CFNetwork/1408.0.4 Darwin/22.5.0", "Accept-Encoding": "gzip, deflate, br", } @@ -289,7 +289,7 @@ def status(self): } r = session.get( - f"{baseUrl}/vehicles/v4/{self.vin}/status", params=params, headers=headers + f"{baseUrl}/vehicles/v5/{self.vin}/status", params=params, headers=headers ) if r.status_code == 200: result = r.json() From 2da449aafb44e09ca6d66aa0572b92e5bc8fa1fb Mon Sep 17 00:00:00 2001 From: steve Date: Tue, 18 Jul 2023 12:32:00 +1000 Subject: [PATCH 09/10] Add support for "Enable debugging" in UI --- custom_components/fordpass/manifest.json | 1 + 1 file changed, 1 insertion(+) diff --git a/custom_components/fordpass/manifest.json b/custom_components/fordpass/manifest.json index fffb648..7c78745 100644 --- a/custom_components/fordpass/manifest.json +++ b/custom_components/fordpass/manifest.json @@ -9,6 +9,7 @@ "integration_type": "device", "iot_class": "cloud_polling", "issue_tracker": "https://github.com/itchannel/fordpass-ha/issues", + "loggers": ["custom_components.fordpass"], "requirements": [], "ssdp": [], "version": "0.1.47", From acf2e4a06cbf82bff7274a657ade9045a1807249 Mon Sep 17 00:00:00 2001 From: steve Date: Tue, 18 Jul 2023 12:35:42 +1000 Subject: [PATCH 10/10] update info.md --- info.md | 1 + 1 file changed, 1 insertion(+) diff --git a/info.md b/info.md index 796e3be..081138f 100644 --- a/info.md +++ b/info.md @@ -4,6 +4,7 @@ - Add option to disable distance conversion when units displaying wrong in certain countries - Add device_class to "last_refresh" sensor - Add Locking/Unlocking status to lock entity +- Enabled support for debugging via the UI ### Version 1.46 - Fix diesel filter error ### Version 1.45