leeyuentuen / polestar_api

Polestar Api - Home Assistant Component
MIT License
112 stars 18 forks source link

Failed to update sensor async update #52

Closed gjsiiger closed 6 months ago

gjsiiger commented 6 months ago

I have been using the integration since the first release, and almost all of the issues have been solved during the rapid releases :)

My installation throws the error: "Failed to update sensor async update" and then it just stops collecting data, and that is the last details in the debug log (the last two lines below here)

2023-12-30 03:00:20.611 DEBUG (MainThread) [custom_components.polestar_api.pypolestar.polestar] {'data': {'getBatteryData': {'averageEnergyConsumptionKwhPer100Km': 23, 'batteryChargeLevelPercentage': 65, 'chargerConnectionStatus': 'CHARGER_CONNECTION_STATUS_CONNECTED', 'chargingCurrentAmps': None, 'chargingPowerWatts': None, 'chargingStatus': 'CHARGING_STATUS_CHARGING', 'estimatedChargingTimeMinutesToTargetDistance': None, 'estimatedChargingTimeToFullMinutes': 180, 'estimatedDistanceToEmptyKm': 200, 'estimatedDistanceToEmptyMiles': 110, 'eventUpdatedTimestamp': {'iso': '2023-12-30T01:57:08.000Z', 'unix': '1703901428', 'typename': 'EventUpdatedTimestamp'}, 'typename': 'Battery'}}} 2023-12-30 03:00:39.085 WARNING (MainThread) [custom_components.polestar_api.sensor] Failed to update sensor async update

However there are som previous errors in the debug log, but as you can see they are older. Seems like the async update is causing the issue ?

2023-12-27 15:40:47.214 WARNING (MainThread) [custom_components.polestar_api.sensor] Failed to update sensor async update 2023-12-28 09:48:05.109 WARNING (MainThread) [custom_components.polestar_api.sensor] Failed to update sensor async update 2023-12-28 12:04:26.994 WARNING (MainThread) [custom_components.polestar_api.pypolestar.polestar] Failed to get data Get GraphQL error: 2023-12-28 21:57:30.232 ERROR (MainThread) [custom_components.polestar_api.pypolestar.polestar] User not authenticated 2023-12-28 21:57:30.922 ERROR (MainThread) [custom_components.polestar_api.pypolestar.polestar] User not authenticated 2023-12-29 01:57:46.315 ERROR (MainThread) [custom_components.polestar_api.pypolestar.polestar] User not authenticated 2023-12-29 01:57:46.877 ERROR (MainThread) [custom_components.polestar_api.pypolestar.polestar] User not authenticated 2023-12-29 10:13:39.094 WARNING (MainThread) [custom_components.polestar_api.sensor] Failed to update sensor async update

/Gorm

Ottmar0815 commented 6 months ago

Yes, i have the same error (API Status shows "OK"), but no data update will be done.

============ Log Begin ============

2023-12-30 03:00:19.518 DEBUG (MainThread) [custom_components.polestar_api.pypolestar.polestar] {'data': {'getOdometerData': {'averageSpeedKmPerHour': 50, 'eventUpdatedTimestamp': {'iso': '2023-12-28T14:08:28.000Z', 'unix': '1703772508', 'typename': 'EventUpdatedTimestamp'}, 'odometerMeters': 43860500, 'tripMeterAutomaticKm': 0.5, 'tripMeterManualKm': 104.8, 'typename': 'Odometer'}}} 2023-12-30 03:00:20.368 DEBUG (MainThread) [custom_components.polestar_api.pypolestar.polestar] {'data': {'getBatteryData': {'averageEnergyConsumptionKwhPer100Km': 26, 'batteryChargeLevelPercentage': 53, 'chargerConnectionStatus': 'CHARGER_CONNECTION_STATUS_CONNECTED', 'chargingCurrentAmps': None, 'chargingPowerWatts': None, 'chargingStatus': 'CHARGING_STATUS_IDLE', 'estimatedChargingTimeMinutesToTargetDistance': None, 'estimatedChargingTimeToFullMinutes': 0, 'estimatedDistanceToEmptyKm': 180, 'estimatedDistanceToEmptyMiles': 110, 'eventUpdatedTimestamp': {'iso': '2023-12-29T20:21:58.000Z', 'unix': '1703881318', 'typename': 'EventUpdatedTimestamp'}, 'typename': 'Battery'}}} 2023-12-30 03:00:34.521 DEBUG (MainThread) [custom_components.polestar_api.pypolestar.polestar] {'data': {'getOdometerData': {'averageSpeedKmPerHour': 50, 'eventUpdatedTimestamp': {'iso': '2023-12-28T14:08:28.000Z', 'unix': '1703772508', 'typename': 'EventUpdatedTimestamp'}, 'odometerMeters': 43860500, 'tripMeterAutomaticKm': 0.5, 'tripMeterManualKm': 104.8, 'typename': 'Odometer'}}} 2023-12-30 03:00:39.532 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.polestar_2_estimate_distance_to_empty_miles fails Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/anyio/streams/tls.py", line 133, in _call_sslobject_method result = func(*args) ^^^^^^^^^^^ File "/usr/local/lib/python3.11/ssl.py", line 921, in read v = self._sslobj.read(len) ^^^^^^^^^^^^^^^^^^^^^^ ssl.SSLWantReadError: The operation did not complete (read) (_ssl.c:2580)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/anyio/_core/_tasks.py", line 115, in fail_after yield cancel_scope File "/usr/local/lib/python3.11/site-packages/httpcore/_backends/anyio.py", line 34, in read return await self._stream.receive(max_bytes=max_bytes) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/anyio/streams/tls.py", line 198, in receive data = await self._call_sslobject_method(self._ssl_object.read, max_bytes) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/anyio/streams/tls.py", line 140, in _call_sslobject_method data = await self.transport_stream.receive() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 1103, in receive await self._protocol.read_event.wait() File "/usr/local/lib/python3.11/asyncio/locks.py", line 213, in wait await fut asyncio.exceptions.CancelledError: Cancelled by cancel scope 7f87f1bf10

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/httpcore/_exceptions.py", line 10, in map_exceptions yield File "/usr/local/lib/python3.11/site-packages/httpcore/_backends/anyio.py", line 32, in read with anyio.fail_after(timeout): File "/usr/local/lib/python3.11/contextlib.py", line 155, in exit self.gen.throw(typ, value, traceback) File "/usr/local/lib/python3.11/site-packages/anyio/_core/_tasks.py", line 118, in fail_after raise TimeoutError TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 66, in map_httpcore_exceptions yield File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 366, in handle_async_request resp = await self._pool.handle_async_request(req) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/httpcore/_async/connection_pool.py", line 262, in handle_async_request raise exc File "/usr/local/lib/python3.11/site-packages/httpcore/_async/connection_pool.py", line 245, in handle_async_request response = await connection.handle_async_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/httpcore/_async/connection.py", line 103, in handle_async_request return await self._connection.handle_async_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/httpcore/_async/http11.py", line 133, in handle_async_request raise exc File "/usr/local/lib/python3.11/site-packages/httpcore/_async/http11.py", line 111, in handle_async_request ) = await self._receive_response_headers(**kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/httpcore/_async/http11.py", line 176, in _receive_response_headers event = await self._receive_event(timeout=timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/httpcore/_async/http11.py", line 212, in _receive_event data = await self._network_stream.read( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/httpcore/_backends/anyio.py", line 31, in read with map_exceptions(exc_map): File "/usr/local/lib/python3.11/contextlib.py", line 155, in exit self.gen.throw(typ, value, traceback) File "/usr/local/lib/python3.11/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions raise to_exc(exc) from exc httpcore.ReadTimeout

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 698, in async_update_ha_state await self.async_device_update() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 959, in async_device_update await self.async_update() File "/config/custom_components/polestar_api/sensor.py", line 530, in async_update await self._device.async_update() File "/config/custom_components/polestar_api/polestar.py", line 50, in async_update await self.polestarApi.get_ev_data(self.vin) File "/config/custom_components/polestar_api/pypolestar/polestar.py", line 131, in get_ev_data await call_api(lambda: self._get_battery_data(vin)) File "/config/custom_components/polestar_api/pypolestar/polestar.py", line 122, in call_api await func() File "/config/custom_components/polestar_api/pypolestar/polestar.py", line 79, in _get_battery_data result = await self.get_graph_ql(params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/polestar_api/pypolestar/polestar.py", line 154, in get_graph_ql result = await self._client_session.get(url, params=params, headers=headers) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1757, in get return await self.request( ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1530, in request return await self.send(request, auth=auth, follow_redirects=follow_redirects) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1617, in send response = await self._send_handling_auth( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1645, in _send_handling_auth response = await self._send_handling_redirects( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1682, in _send_handling_redirects response = await self._send_single_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1719, in _send_single_request response = await transport.handle_async_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 365, in handle_async_request with map_httpcore_exceptions(): File "/usr/local/lib/python3.11/contextlib.py", line 155, in exit self.gen.throw(typ, value, traceback) File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 83, in map_httpcore_exceptions raise mapped_exc(message) from exc httpx.ReadTimeout

============ Log End ============

Ottmar0815 commented 6 months ago

After reload of the integration it works fine again.

ohaue commented 6 months ago

I see the same. Started yesterday and have happened for me 2 times. Once yesterday where I just reloaded and once again just now.

Using version 1.2.4 of the integration.

Best regards Otto

goossensk commented 6 months ago

I didn't look to the logs yet but my integration is also not updating its data. When I restart Hass it's updating one time and then it seems to stop again.

gjsiiger commented 6 months ago

It stopped again, and the logs look diffrent now: There are 403 forbidden - not sure if it's on Polestar server side.

Logger: custom_components.polestar_api.pypolestar.polestar
Source: custom_components/polestar_api/pypolestar/polestar.py:171
Integration: Polestar API (documentation)
First occurred: 17:47:47 (18 occurrences)
Last logged: 18:39:48

403: Forbidden
ohaue commented 6 months ago

Seems to be working for me today - Battery last update entity keeps getting updated :-)

leeyuentuen commented 6 months ago

let's take look at the new beta if this solved the auth issue here: https://github.com/leeyuentuen/polestar_api/releases/tag/1.2.7

gjsiiger commented 6 months ago

Seems to be working quite good now in the latest version.