leeyuentuen / polestar_api

Polestar Api - Home Assistant Component
MIT License
131 stars 23 forks source link

Data doesn't refresh unless I reload the integration #25

Closed 3shirts closed 9 months ago

3shirts commented 9 months ago

I'm not sure if this is by design, perhaps due to low polling frequency, but I don't see updated data in HA unless I manually reload the integration, at which point it pulls the latest. I am using 1.0.2

leeyuentuen commented 9 months ago

can you take a look at 1.0.3 beta version. there is more logging added to investigate the issue.

leeyuentuen commented 9 months ago

it could be that there is something with token timeout but maybe we will see more in the log in that beta branch

3shirts commented 9 months ago

Thanks. I've updated to 1.0.3. Do you want debug logging and over what period?

leeyuentuen commented 9 months ago

you can maybe start the debug logging and stop them when the problem exists

3shirts commented 9 months ago

How often is it supposed to refresh so I know what qualifies as a problem?

leeyuentuen commented 9 months ago

normally refresh every 10-15sec with caching you will see different on ha if the value change, so if your battery is 50% and you didn't drive, it will keep 'not updated' unless it has been changed value

3shirts commented 9 months ago

Did a quick log for 10 minutes (during which it didn't update). The log looks ok to my untrained eye. I'll try more tomorrow when I'm home.

error_log.txt

leeyuentuen commented 9 months ago

it seems i saw there is a possibility to crash and stop fetching. maybe try this new beta version https://github.com/leeyuentuen/polestar_api/releases/tag/1.0.4

leeyuentuen commented 9 months ago

seems polestar got issue here: but i need to catch them in de code

2023-12-22 04:11:36.165 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.polestar_1283_charging_power_watts fails Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 696, in async_update_ha_state await self.async_device_update() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 957, in async_device_update await self.async_update() File "/config/custom_components/polestar_api/sensor.py", line 524, in async_update await self._device.get_ev_data() File "/config/custom_components/polestar_api/polestar_api.py", line 227, in get_ev_data await self.getOdometerData() File "/config/custom_components/polestar_api/polestar_api.py", line 208, in getOdometerData result = await self.get_odo_data() ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/polestar_api/polestar_api.py", line 261, in get_odo_data return await self.get_graph_ql(params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/polestar_api/polestar_api.py", line 239, in get_graph_ql resultData = await result.json() ^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/aiohttp_client.py", line 84, in json return await super().json(*args, loads=loads, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/client_reqrep.py", line 1104, in json raise ContentTypeError( aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/html; charset=utf-8', url=URL('https://pc-api.polestar.com/eu-north-1/my-star/?query=query+GetOdometerData($vin:+String!)+%7B+getOdometerData(vin:+$vin)+%7B+averageSpeedKmPerHour+eventUpdatedTimestamp+%7B+iso+unix+__typename+%7D+odometerMeters+tripMeterAutomaticKm+tripMeterManualKm+__typename+%7D%7D&operationName=GetOdometerData&

leeyuentuen commented 9 months ago

@3shirts this beta version i suppose it will works: https://github.com/leeyuentuen/polestar_api/releases/tag/1.1.2

4integration commented 9 months ago

Installed

leeyuentuen commented 9 months ago

Installed

still got issue?

leeyuentuen commented 9 months ago

i'll close this issue. I suppose it should work (on version 1.2.3), if the issue still exist, open a new issue with some log for better follow up

4integration commented 9 months ago

Looks like it works, thanks 👍

3shirts commented 9 months ago

Just to confirm that it does indeed seem fixed for me. I am on the latest version, currently 1.2.4 and all good. Thanks for the quick work.