Skip to content

Commit

Permalink
Merge pull request #23 from itchannel/active_dev
Browse files Browse the repository at this point in the history
Added "refresh" service and window sensors
  • Loading branch information
itchannel authored Nov 21, 2020
2 parents dffe1dc + 991d630 commit bf0dcd4
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 2 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ Use HACS and add as a custom repo. Once the integration is installed go to your
- Password (Fordpass App)
- VIN Number

## Usage
Your car must have the lastest onboard modem functionality and have registered/authorised the fordpass application

### Car Refresh
I have added a service to poll the car for updates, due to the battery drain I have left this up to you to set the interval. The service to be called is "refresh_status" and can be accessed in home assistant using "fordpas.refresh_status" with no parameters.

**This will take up to 5 mins to update from the car once the service has been run**


## Currently Working

Expand All @@ -23,10 +31,11 @@ Use HACS and add as a custom repo. Once the integration is installed go to your
- Alarm Status
- Individual door statuses
- Remote Start
- Window Status (Only if your car supports it!)
- Last Car Refresh status


## Coming Soon

- Code tidy up
- Alarm event (Anyone have the json output for this event would be appreciated :) )
- Window Status (Anyone have the json output for this event would be appreciated :))
16 changes: 16 additions & 0 deletions custom_components/fordpass/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,25 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
hass.config_entries.async_forward_entry_setup(entry, component)
)

async def async_refresh_status_service(service_call):
await hass.async_add_executor_job(
refresh_status, hass, service_call, coordinator
)

hass.services.async_register(
DOMAIN,
"refresh_status",
async_refresh_status_service,
)

return True


def refresh_status(service, hass, coordinator):
_LOGGER.debug("Running Service")
coordinator.vehicle.requestUpdate()


async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Unload a config entry."""
unload_ok = all(
Expand Down
2 changes: 1 addition & 1 deletion custom_components/fordpass/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""Config flow for FordPass integration."""
import logging

from .fordpass_new import Vehicle
import voluptuous as vol
from homeassistant import config_entries, core, exceptions
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME

from .const import DOMAIN, VIN # pylint:disable=unused-import
from .fordpass_new import Vehicle

_LOGGER = logging.getLogger(__name__)

Expand Down
24 changes: 24 additions & 0 deletions custom_components/fordpass/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
"alarm",
"ignitionStatus",
"doorStatus",
"windowPosition",
"lastRefresh",
]
sensors = []
for snr in snrarray:
Expand Down Expand Up @@ -60,6 +62,15 @@ def get_value(self, ftype):
if value["value"] != "Closed":
return "Open"
return "Closed"
elif self.sensor == "windowPosition":
if self.coordinator.data[self.sensor] == None:
return "Unsupported"
for key, value in self.coordinator.data[self.sensor].items():
if value["value"] != "Fully_Closed":
return "Open"
return "Closed"
elif self.sensor == "lastRefresh":
return self.coordinator.data[self.sensor]
elif ftype == "measurement":
if self.sensor == "odometer":
return "km"
Expand All @@ -79,6 +90,10 @@ def get_value(self, ftype):
return None
elif self.sensor == "doorStatus":
return None
elif self.sensor == "windowsPosition":
return None
elif self.sensor == "lastRefresh":
return None
elif ftype == "attribute":
if self.sensor == "odometer":
return self.coordinator.data[self.sensor].items()
Expand All @@ -101,6 +116,15 @@ def get_value(self, ftype):
for key, value in self.coordinator.data[self.sensor].items():
doors[key] = value["value"]
return doors
elif self.sensor == "windowPosition":
if self.coordinator.data[self.sensor] == None:
return None
windows = dict()
for key, value in self.coordinator.data[self.sensor].items():
windows[key] = value["value"]
return windows
elif self.sensor == "lastRefresh":
return None

@property
def name(self):
Expand Down
2 changes: 2 additions & 0 deletions custom_components/fordpass/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
refresh_status:
description: "Poll car for latest status (Takes up to 5mins to update once this function has been run!)"
7 changes: 7 additions & 0 deletions info.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@

# **Changelog**
### Version 1.04
- Added window position status
- Added service "fresh_status" to allow for polling the car at a set interval or event
- Added Last Refreshed sensor, so you can see when the car was last polled for data
- Added some more debug logging

### Version 1.03
- Added door status
- Added token saving
- Added car poll refresh
Expand Down

0 comments on commit bf0dcd4

Please sign in to comment.