Skip to content

Commit

Permalink
Merge pull request #272 from itchannel/1.47
Browse files Browse the repository at this point in the history
1.47
  • Loading branch information
itchannel committed Jul 18, 2023
2 parents 6402a7b + 1e74516 commit 2f2f7c6
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 16 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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

Expand Down
9 changes: 9 additions & 0 deletions custom_components/fordpass/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -123,6 +126,12 @@ async def handle_reload(service):
handle_reload
)

hass.services.async_register(
DOMAIN,
"poll_api",
poll_api_service
)

return True


Expand Down
10 changes: 9 additions & 1 deletion custom_components/fordpass/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion custom_components/fordpass/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -38,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",
Expand Down
4 changes: 2 additions & 2 deletions custom_components/fordpass/fordpass_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}

Expand Down Expand Up @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions custom_components/fordpass/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion custom_components/fordpass/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
"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.46",
"version": "0.1.47",
"zeroconf": []
}
17 changes: 11 additions & 6 deletions custom_components/fordpass/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -457,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
3 changes: 3 additions & 0 deletions custom_components/fordpass/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
1 change: 1 addition & 0 deletions custom_components/fordpass/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions custom_components/fordpass/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions custom_components/fordpass/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions custom_components/fordpass/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions info.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
## **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
- Add Locking/Unlocking status to lock entity
- Enabled support for debugging via the UI
### Version 1.46
- Fix diesel filter error
### Version 1.45
Expand Down

0 comments on commit 2f2f7c6

Please sign in to comment.