fars-fede-fire / volvoaaos

Home Assistant custom component for Volvo AAOS vehicles
MIT License
8 stars 2 forks source link

VolvoAAOS Failed to set up entities #70

Open malrogers7 opened 1 month ago

malrogers7 commented 1 month ago

System Health details

System Information

version core-2024.8.1
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.12.4
os_name Linux
os_version 6.6.31-haos-raspi
arch aarch64
timezone Europe/London
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 5000 Installed Version | 1.34.0 Stage | running Available Repositories | 1386 Downloaded Repositories | 16
AccuWeather can_reach_server | ok -- | -- remaining_requests | 34
Home Assistant Cloud logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Home Assistant Supervisor host_os | Home Assistant OS 12.4 -- | -- update_channel | stable supervisor_version | supervisor-2024.08.0 agent_version | 1.6.0 docker_version | 26.1.4 disk_total | 28.5 GB disk_used | 8.8 GB healthy | true supported | true host_connectivity | true supervisor_connectivity | true ntp_synchronized | true virtualization | board | rpi4-64 supervisor_api | ok version_api | ok installed_addons | Mosquitto broker (6.4.1), Cloudflared (5.1.17), Let's Encrypt (5.0.27), NGINX Home Assistant SSL proxy (3.9.0), Samba Backup (5.2.0), Zigbee2MQTT (1.39.1-1), File editor (5.8.0), Piper (1.5.2), Whisper (2.1.2), Samba share (12.3.2), Volvo2Mqtt (1.9.6)
Dashboards dashboards | 5 -- | -- resources | 12 views | 28 mode | storage
Recorder oldest_recorder_run | 3 August 2024 at 10:28 -- | -- current_recorder_run | 13 August 2024 at 19:50 estimated_db_size | 737.32 MiB database_engine | sqlite database_version | 3.45.3

Checklist

Describe the issue

I have managed to set up VolvoAAOS, but the Volvo API is so buggy, it does not manage to set up in HA.

I have looked on the Volvo Developer account and I can access the Recharge Status endpoint. However, every 4 out of 5 attempts or so return a '401 access denied'. Then 1 out of 5 is '200' and data is returned.

I could see this in action when trying to set up the integration: it took 4 or 5 attempts to successfully login and get it to set up, presumably on the first few attempts, Volvo incorrectly responded '401'.

However, once I got through the config flow, it refuses to set up any entities. Looking at the debug logs, it appears that Volvo is returning lots of '401' and '410' errors. This seems to be an error with Volvo, but is there a way to ignore those until the Volvo API returns a '200' status?

I have a 2024 XC40, and I have seen other people have issues with this, but I do get a full suite of data in the Volvo Developer Portal under the recharge-status/ Energy API

Reproduction steps

  1. Install repository via HACS
  2. Add integration - complete username, password and VCC-API-Key- keep trying until it sets up
  3. Integration installs, But HA states failed to set up ...

Debug logs


System logs:
Logger: homeassistant.config_entries
Source: config_entries.py:604
First occurred: 22:57:50 (4 occurrences)
Last logged: 22:58:10

Error setting up entry Volvo - XC40 for volvoaaos
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 604, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/volvoaaos/__init__.py", line 44, in async_setup_entry
    energy_data = await update_energy(energy=energy, all_recharge_available=entry.data[CONF_ALL_RECHARGE_AVAILABLE])
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/volvoaaos/coordinator.py", line 93, in update_energy
    energy_data = await energy_call.get_battery_charge_level()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/volvoaaos/volvo.py", line 143, in get_battery_charge_level
    response = await self._request(url=url, headers=headers)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/volvoaaos/volvo.py", line 47, in _request
    response.raise_for_status()
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 1093, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 401, message='Unauthorized', url='https://api.volvocars.com/connected-vehicle/v1/vehicles/YV1XZEPT4R2305143/battery-charge-level'

Full debug logs are too long to create issue but can be provided.

Example responses:
volvoaaos
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 604, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/volvoaaos/__init__.py", line 44, in async_setup_entry
    energy_data = await update_energy(energy=energy, all_recharge_available=entry.data[CONF_ALL_RECHARGE_AVAILABLE])
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/volvoaaos/coordinator.py", line 93, in update_energy
    energy_data = await energy_call.get_battery_charge_level()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/volvoaaos/volvo.py", line 143, in get_battery_charge_level
    response = await self._request(url=url, headers=headers)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/volvoaaos/volvo.py", line 47, in _request
    response.raise_for_status()
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 1093, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 401, message='Unauthorized', url='https://api.volvocars.com/connected-vehicle/v1/vehicles/YV1XZEPT4R2305143/battery-charge-level'
2024-08-13 20:08:37.601 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Volvo - Volvo XC40 for volvoaaos
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 604, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/volvoaaos/__init__.py", line 44, in async_setup_entry
    energy_data = await update_energy(energy=energy, all_recharge_available=entry.data[CONF_ALL_RECHARGE_AVAILABLE])
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/volvoaaos/coordinator.py", line 93, in update_energy
    energy_data = await energy_call.get_battery_charge_level()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/volvoaaos/volvo.py", line 143, in get_battery_charge_level
    response = await self._request(url=url, headers=headers)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/volvoaaos/volvo.py", line 47, in _request
    response.raise_for_status()
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 1093, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 410, message='Gone', url='https://api.volvocars.com/connected-vehicle/v1/vehicles/YV1XZEPT4R2305143/battery-charge-level'
2024-08-13 20:09:09.534 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Volvo - Volvo XC40 for volvoaaos

Diagnostics dump

No response

fars-fede-fire commented 3 weeks ago

Thank you reaching out and sorry for the late answer.

It should be possible to add some kind of retry until status code 200 is returned. I am not sure if the it counts towards the daily API limit.

I am quite busy at the moment so not sure when this will be fixed.

malrogers7 commented 2 weeks ago

Thank you. Please do not worry about it if you do not have time. It may not even solve the issue, given how odd the Volvo API is. At the moment, I am using the Volvo2MQTT add-on. I would prefer to use an integration rather than having to route it through MQTT, but it seems ok for now.