Skip to content

Commit 294caa0

Browse files
author
marq24
committed
fixing service "force refresh" as reported in #129
1 parent 64c22b1 commit 294caa0

File tree

3 files changed

+18
-25
lines changed

3 files changed

+18
-25
lines changed

custom_components/fordpass/__init__.py

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,26 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
125125
# SERVICES from here...
126126
# simple service implementations (might be moved to separate service.py)
127127
async def async_refresh_status_service(call: ServiceCall):
128-
await hass.async_add_executor_job(service_refresh_status, hass, call, coordinator)
129-
await asyncio.sleep(15)
130-
await coordinator.async_refresh()
128+
_LOGGER.debug(f"Running Service 'refresh_status'")
129+
status = await coordinator.bridge.request_update()
130+
if status == 401:
131+
_LOGGER.debug(f"[@{coordinator.vli}] refresh_status: Invalid VIN?! (status 401)")
132+
elif status in [200, 201, 202]:
133+
_LOGGER.debug(f"[@{coordinator.vli}] refresh_status: Refresh sent")
134+
135+
await asyncio.sleep(10)
136+
await coordinator.async_request_refresh_force_classic_requests()
131137

132138
async def async_clear_tokens_service(call: ServiceCall):
133-
await hass.async_add_executor_job(service_clear_tokens, hass, call, coordinator)
139+
#await hass.async_add_executor_job(service_clear_tokens, hass, call, coordinator)
140+
"""Clear the token file in config directory, only use in emergency"""
141+
_LOGGER.debug(f"Running Service 'clear_tokens'")
142+
await coordinator.bridge.clear_token()
134143
await asyncio.sleep(5)
135-
await coordinator.async_request_refresh()
144+
await coordinator.async_request_refresh_force_classic_requests()
136145

137146
async def poll_api_service(call: ServiceCall):
138-
await coordinator.async_request_refresh()
147+
await coordinator.async_request_refresh_force_classic_requests()
139148

140149
async def handle_reload_service(call: ServiceCall):
141150
"""Handle reload service call."""
@@ -172,22 +181,6 @@ async def async_update_options(hass, config_entry):
172181
hass.config_entries.async_update_entry(config_entry, options=options)
173182

174183

175-
def service_refresh_status(hass, service, coordinator):
176-
"""Get the latest vehicle status from vehicle, actively polls the car"""
177-
_LOGGER.debug(f"Running Service 'refresh_status'")
178-
status = coordinator.bridge.request_update()
179-
if status == 401:
180-
_LOGGER.debug(f"[@{coordinator.vli}] refresh_status: Invalid VIN?! (status 401)")
181-
elif status == 200:
182-
_LOGGER.debug(f"[@{coordinator.vli}] refresh_status: Refresh sent")
183-
184-
185-
def service_clear_tokens(hass, service, coordinator):
186-
"""Clear the token file in config directory, only use in emergency"""
187-
_LOGGER.debug(f"Running Service 'clear_tokens'")
188-
coordinator.bridge.clear_token()
189-
190-
191184
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
192185
"""Unload a config entry."""
193186
_LOGGER.debug(f"async_unload_entry() called for entry: {config_entry.entry_id}")

custom_components/fordpass/fordpass_bridge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,9 +1902,9 @@ async def unlock(self):
19021902
"""Issue an unlock command to the doors"""
19031903
return await self.__request_and_poll_command_autonomic(baseurl=AUTONOMIC_URL, write_command="unlock")
19041904

1905-
def request_update(self):
1905+
async def request_update(self):
19061906
"""Send request to vehicle for update"""
1907-
status = self.__request_and_poll_command_autonomic(baseurl=AUTONOMIC_URL, write_command="statusRefresh")
1907+
status = await self.__request_and_poll_command_autonomic(baseurl=AUTONOMIC_URL, write_command="statusRefresh")
19081908
return status
19091909

19101910

custom_components/fordpass/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
"loggers": ["custom_components.fordpass"],
1313
"requirements": [],
1414
"ssdp": [],
15-
"version": "2025.11.1",
15+
"version": "2025.11.2",
1616
"zeroconf": []
1717
}

0 commit comments

Comments
 (0)