itchannel / fordpass-ha

Fordpass integration for Home Assistant
301 stars 53 forks source link

FordPass integration looses connection at random intervals #82

Closed thoppenreys1 closed 3 years ago

thoppenreys1 commented 3 years ago

HA Version - 2021.2.3 FordPass Integration Version - 1.14

This integration has worked great since it was officially released in HACS until a couple of weeks ago. After successfully authenticating, entities updating as they should, etc...at random times HA looses connection somehow, all entities become 'unavailable' and will not reconnect (even with HA restart) until the integration is either deleted and readded, or a refresh is performed from the FordPass App. I wrote an automation that performed a refresh every 30 minutes which worked fine for a few hours, but them HA lost connection 12 minutes after the automation ran.

Here's what I'm seeing in my logs:

Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 169, in _new_conn conn = connection.create_connection( File "/usr/local/lib/python3.8/site-packages/urllib3/util/connection.py", line 73, in create_connection for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): File "/usr/local/lib/python3.8/socket.py", line 918, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno -3] Try again

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 699, in urlopen httplib_response = self._make_request( File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 382, in _make_request self._validate_conn(conn) File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 1010, in _validate_conn conn.connect() File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 353, in connect conn = self._new_conn() File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 181, in _new_conn raise NewConnectionError( urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7fa9f9a497f0>: Failed to establish a new connection: [Errno -3] Try again

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 439, in send resp = conn.urlopen( File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 755, in urlopen retries = retries.increment( File "/usr/local/lib/python3.8/site-packages/urllib3/util/retry.py", line 573, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='usapi.cv.ford.com', port=443): Max retries exceeded with url: /api/vehicles/v2/1############978/status (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fa9f9a497f0>: Failed to establish a new connection: [Errno -3] Try again'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/automation/init.py", line 404, in async_trigger await self.action_script.async_run( File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1033, in async_run await asyncio.shield(run.async_run()) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 246, in async_run await self._async_step(log_exceptions=False) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 254, in _async_step await getattr( File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 464, in _async_call_service_step await service_task File "/usr/src/homeassistant/homeassistant/core.py", line 1455, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1490, in _execute_service await handler.job.target(service_call) File "/config/custom_components/fordpass/init.py", line 68, in async_refresh_status_service await hass.async_add_executor_job( File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, self.kwargs) File "/config/custom_components/fordpass/init.py", line 99, in refresh_status coordinator.vehicle.requestUpdate() File "/config/custom_components/fordpass/fordpass_new.py", line 238, in requestUpdate status = self.makeRequest( File "/config/custom_components/fordpass/fordpass_new.py", line 254, in makeRequest return getattr(requests, method.lower())( File "/usr/local/lib/python3.8/site-packages/requests/api.py", line 134, in put return request('put', url, data=data, kwargs) File "/usr/local/lib/python3.8/site-packages/requests/api.py", line 61, in request return session.request(method=method, url=url, kwargs) File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 542, in request resp = self.send(prep, send_kwargs) File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 655, in send r = adapter.send(request, **kwargs) File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 516, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPSConnectionPool(host='usapi.cv.ford.com', port=443): Max retries exceeded with url: /api/vehicles/v2/1#############978/status (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fa9f9a497f0>: Failed to establish a new connection: [Errno -3] Try again'))

......

2021-02-11 21:41:53 WARNING (MainThread) [custom_components.fordpass] 'vehiclestatus' 2021-02-11 21:41:53 WARNING (MainThread) [custom_components.fordpass] Error communicating with FordPass for 1###########978 2021-02-11 21:41:53 ERROR (MainThread) [custom_components.fordpass] Error fetching fordpass data: Error communicating with FordPass for 1###########978 2021-02-11 21:51:53 WARNING (MainThread) [custom_components.fordpass] 'vehiclestatus' 2021-02-11 21:51:53 WARNING (MainThread) [custom_components.fordpass] Error communicating with FordPass for 1###########978

itchannel commented 3 years ago

@thoppenreys1 from what I can see in the logs the integration is having issues accessing the Fordpass API. requests.exceptions.ConnectionError: HTTPSConnectionPool(host='usapi.cv.ford.com', port=443): Max retries exceeded with url: /api/vehicles/v2/1#############978/status (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fa9f9a497f0>: Failed to establish a new connection: [Errno -3] Try again'))

I've seen this issue before on the latest HA when there is a DNS issue. That could of been caused by the latest HA update, are you running HA in docker by any chance? Best way to check if that is the issue is to change the DNS server to 1.1.1.1 in /etc/resolv.conf inside the docker/HA instance and then restart HA from the HA menu and see if it then resolves/works.

Also running the refresh service only polls the car so would just create greater battery drain but wouldn't help in this situation.

itchannel commented 3 years ago

@thoppenreys1 any progress on this otherwise I'll close the issue as its a local instance issue.