fars-fede-fire / volvoaaos

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

Error setting up entry Volvo - XC40 for volvoaaos #20

Closed rene-neimann closed 11 months ago

rene-neimann commented 11 months ago

System Health details

System Information

version core-2023.10.3
installation_type Home Assistant Container
dev false
hassio false
docker true
user root
virtualenv false
python_version 3.11.5
os_name Linux
os_version 4.4.302+
arch x86_64
timezone Europe/Tallinn
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 4976 Installed Version | 1.33.0 Stage | running Available Repositories | 1396 Downloaded Repositories | 21 HACS Data | ok
Home Assistant Cloud logged_in | true -- | -- subscription_expiration | November 13, 2023 at 02:00 relayer_connected | true relayer_region | eu-central-1 remote_enabled | true remote_connected | true alexa_enabled | false google_enabled | true remote_server | eu-central-1-14.ui.nabu.casa certificate_status | ready can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Dashboards dashboards | 1 -- | -- resources | 7 views | 13 mode | storage
Recorder oldest_recorder_run | October 29, 2023 at 20:15 -- | -- current_recorder_run | November 1, 2023 at 10:28 estimated_db_size | 929.42 MiB database_engine | sqlite database_version | 3.41.2

Checklist

Describe the issue

In Volvo Cars app everything works for my XC40 Recharge Pure Electric MY2024 but I'm unable to complete the setup of this HACS integration. I've properly entered username, password and VCC API key in HA and even see the count of API calls increasing for the application I created on https://developer.volvocars.com/account/ but in HA the integration status is "Failed to set up" and I see an error messages in logs every time I reload the integration.

Reproduction steps

  1. Install the integration
  2. Enter username/password/API key
  3. Integration fails to start and error messages appear in logs.

Debug logs

This error originated from a custom integration.

Logger: homeassistant
Source: custom_components/volvoaaos/volvo.py:130
Integration: Volvo AAOS (documentation, issues)
First occurred: 10:29:25 (13 occurrences)
Last logged: 10:41:26

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/config/custom_components/volvoaaos/coordinator.py", line 71, in update_coordinator_data
    energy = await update_energy(self.energy, access_token, vcc_api_key, vin)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/volvoaaos/coordinator.py", line 89, in update_energy
    energy_data = await energy_call.get_recharge_status()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/volvoaaos/volvo.py", line 130, in get_recharge_status
    return RechargeModel.parse_obj(response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pydantic/main.py", line 526, in pydantic.main.BaseModel.parse_obj
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 5 validation errors for RechargeModel
data -> batteryChargeLevel
  field required (type=value_error.missing)
data -> electricRange
  field required (type=value_error.missing)
data -> estimatedChargingTime
  field required (type=value_error.missing)
data -> chargingConnectionStatus
  field required (type=value_error.missing)
data -> chargingSystemStatus
  field required (type=value_error.missing)

Logger: homeassistant.config_entries
Source: config_entries.py:399
First occurred: 10:28:29 (2 occurrences)
Last logged: 10:41:40

Error setting up entry Volvo - XC40 for volvoaaos
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 399, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/volvoaaos/__init__.py", line 51, in async_setup_entry
    energy_data = await energy.get_recharge_status()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/volvoaaos/volvo.py", line 130, in get_recharge_status
    return RechargeModel.parse_obj(response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pydantic/main.py", line 526, in pydantic.main.BaseModel.parse_obj
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 5 validation errors for RechargeModel
data -> batteryChargeLevel
  field required (type=value_error.missing)
data -> electricRange
  field required (type=value_error.missing)
data -> estimatedChargingTime
  field required (type=value_error.missing)
data -> chargingConnectionStatus
  field required (type=value_error.missing)
data -> chargingSystemStatus
  field required (type=value_error.missing)

Diagnostics dump

No response

fars-fede-fire commented 11 months ago

It seams that it does not get data when requesting the energy api. What does your response look like from: https://developer.volvocars.com/apis/energy/v1/specification/ ?

rene-neimann commented 11 months ago

@fars-fede-fire

data part is empty for some reason:

image

rene-neimann commented 11 months ago

Do I need to publish my Volvo application to make it accessible from HA?

image

rene-neimann commented 11 months ago

Seems to work correctly on a different API endpoint:

image

fars-fede-fire commented 11 months ago

As long as you have a vcc api key you do not need to make it public.

This integration uses the 'recharge status' endpoint. Are you getting data from this on Volvos homepage?

rene-neimann commented 11 months ago

Are you getting data from this on Volvos homepage?

Yes, the same page you asked to check.

What else can we check? I'm happy to help with debugging. I'm based in Estonia.

fars-fede-fire commented 11 months ago

There is a specific endpoint named /recharge-status which returns data from all the other endpoints. What does the endpoint return in your case?

Glad to hear you will help!

rene-neimann commented 11 months ago

Tried many times, data part is always empty for recharge-status (see below) and all other Energy API endpoints. At the same time, other APIs (Connected Vehicle, Extended Vehicle and Location) work as expected and return proper data.

I've sent an e-mail to developer.portal@volvocars.com - let's see if and what they respond.

Any other suggestions?

https://api.volvocars.com/energy/v1/vehicles/XXXXXXXXXXXXX/recharge-status

{ "status": 200, "operationId": "ec01756a-e089-45c7-b6f1-8a7c53f6b0f3", "data": {} }

fars-fede-fire commented 11 months ago

That will require to make a fallback request to all the other api endpoints which is stupid because all the information is available through a single endpoint. I will try to figure something out.

I will be happy to hear the response from Volvo :-)

rene-neimann commented 11 months ago

Fallback wouldn't even be possible -- batteryChargeLevel is the only piece of energy information available in other APIs. I personally suspect the public Energy API is not available for the XC40 Recharge MY2024 model yet. Let's see if and what they respond.

rene-neimann commented 11 months ago

Ah, I'm afraid we're out of luck -- it seems to be a known issue that the energy API endpoints are not supported for XC40 Recharge MY24 yet :/ See the discussion here: https://community.home-assistant.io/t/volvo2mqtt-connect-your-aaos-volvo/585699

I suggest to improve the handling of empty data in /recharge-status endpoint. This way myself and other similar users could still at least leverage the other functions of the integration. WDYT?

Ilpo55 commented 11 months ago

This way myself and other similar users could still at least leverage the other functions of the integration.

Thanks for the investigation.

Can you confirm which functions are working.

(I will get my XC40 Recharge ER (MY24) in December. )

rene-neimann commented 11 months ago

Can you confirm which functions are working.

@fars-fede-fire , which other API endpoints is the integration using? I could test those with my car.

fars-fede-fire commented 11 months ago

I have tried to make a fix. It is rather hacky though... Can you try it out? https://github.com/fars-fede-fire/volvoaaos/tree/fix-unavailable-recharge-status

rene-neimann commented 11 months ago

I tried the new code (I'm 100% sure as I manually uploaded the custom_component directory) but still getting the exact same error messages:

Logger: homeassistant.config_entries Source: config_entries.py:399 First occurred: 16:39:09 (4 occurrences) Last logged: 16:47:43

Error setting up entry Volvo - XC40 for volvoaaos Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 399, in async_setup result = await component.async_setup_entry(hass, self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/volvoaaos/init.py", line 51, in async_setup_entry energy_data = await energy.get_recharge_status() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/volvoaaos/volvo.py", line 130, in get_recharge_status return RechargeModel.parse_obj(response) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pydantic/main.py", line 526, in pydantic.main.BaseModel.parse_obj File "pydantic/main.py", line 341, in pydantic.main.BaseModel.init pydantic.error_wrappers.ValidationError: 5 validation errors for RechargeModel data -> batteryChargeLevel field required (type=value_error.missing) data -> electricRange field required (type=value_error.missing) data -> estimatedChargingTime field required (type=value_error.missing) data -> chargingConnectionStatus field required (type=value_error.missing) data -> chargingSystemStatus field required (type=value_error.missing)

fars-fede-fire commented 11 months ago

Thank you for testing. I have tried to solve it again. Would you mind to try again? https://github.com/fars-fede-fire/volvoaaos/tree/fix-unavailable-recharge-status

rene-neimann commented 11 months ago

Getting the following errors now:

This error originated from a custom integration.

Logger: homeassistant Source: custom_components/volvoaaos/coordinator.py:75 Integration: Volvo AAOS (documentation, issues) First occurred: 20:38:41 (2 occurrences) Last logged: 20:39:06

Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/config/custom_components/volvoaaos/coordinator.py", line 75, in update_coordinator_data energy_data = await update_energy(energy=self.energy, all_recharge_available=self.config_entry.data[CONF_ALL_RECHARGE_AVAILABLE])


KeyError: 'all_recharge_available'

Logger: homeassistant.config_entries
Source: config_entries.py:399
First occurred: 20:38:53 (2 occurrences)
Last logged: 20:39:04

Error setting up entry Volvo - XC40 for volvoaaos
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 399, 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 144, in get_battery_charge_level
    return BatteryChargeLevelModel.parse_obj(response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pydantic/main.py", line 526, in pydantic.main.BaseModel.parse_obj
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for BatteryChargeLevelModel
data -> batteryChargeLevel
  field required (type=value_error.missing)
rene-neimann commented 11 months ago

Also, please consider adding /connected-vehicle/v1/vehicles/asdf/battery-charge-level as a fallback in case energy API returns empty data. This would allow at least seeing battery charge level for MY24 cars for which energy API is not supported.

fars-fede-fire commented 11 months ago

Thank you once again. Sorry I think I misunderstood you. Thought you could get data from some, but not all energy endpoints, but see now when scrolling through this thread that you get the data from the connected vehicle...

Unfortunately I do not have more time this week but will hopefully look into it next week.

rene-neimann commented 11 months ago

So, /connected-vehicle/v1/vehicles/{vin}/battery-charge-level is the only energy-related API endpoint that returns meaningful data for XC40 MY24. It would be very useful to add this endpoint as fallback in case /energy/v1/vehicles/{vin}/recharge-status returns empty data.

fars-fede-fire commented 11 months ago

Now I have created the fallback wit the connected vehicle API. Because a new variable is created during config flow you have to delete the car from Home Assistant and re-add it. You can use the same VCC-API-KEY as before. It is available here: https://github.com/fars-fede-fire/volvoaaos/tree/fix-unavailable-recharge-status

rene-neimann commented 11 months ago

Excellent, works like a charm! I successfully tested the following:

Thank you very much for quick support!

image

rene-neimann commented 11 months ago

Unfortunately, my joy didn't last for long. Later today I wanted to refresh the data manually and reloaded the integration but it failed to start up again. I was on phone and didn't have time to debug so I simply restarted HA, hoping it would resolve the issue but the integration still wouldn't start up. Unfortunately, I didn't capture the logs but I remember seeing a 404 message for some API v2 endpoint. I deleted the integration completely and reinstalled from scratch but I get an "unknown error occurred" message already when submitting username/password/VCC key. I get the following error message every time I try to add my car. Seems to be some issue with getting the VINs. Volvo stuff is at the bottom.

What could be the issue?

Logger: aiohttp.server Source: /usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py:403 First occurred: 21:03:41 (1 occurrences) Last logged: 21:03:41

Error handling request Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request resp = await request_handler(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle resp = await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 117, in impl return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 31, in headers_middleware response = await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 148, in handle result = await handler(request, request.match_info) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 63, in with_admin return await func(self, request, *args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 177, in post return await super().post(request, flow_id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 72, in wrapper result = await method(view, request, data, args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 110, in post result = await self._flow_mgr.async_configure(flow_id, data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 293, in async_configure result = await self._async_handle_step( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 389, in _async_handle_step result: FlowResult = await getattr(flow, method)(user_input) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/volvoaaos/config_flow.py", line 75, in async_step_user return await self.async_step_select_vin() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/volvoaaos/config_flow.py", line 99, in async_step_select_vin response = await connected_vehicle.list_vehicles() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/volvoaaos/volvo.py", line 170, in list_vehicles return GetVinModel.parse_obj(response) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pydantic/main.py", line 526, in pydantic.main.BaseModel.parse_obj File "pydantic/main.py", line 341, in pydantic.main.BaseModel.init pydantic.error_wrappers.ValidationError: 2 validation errors for GetVinModel status field required (type=value_error.missing) operationId field required (type=value_error.missing)