fars-fede-fire / volvoaaos

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

Failure when setting up integration #23

Closed fars-fede-fire closed 1 year ago

fars-fede-fire commented 1 year 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)

Originally posted by @rene-neimann in https://github.com/fars-fede-fire/volvoaaos/issues/20#issuecomment-1799591756

fars-fede-fire commented 1 year ago

@rene-neimann I have created a new issue and closed the other as I do not think they are related.

I think there is a problem on the Volvo server right now but I am not at my computer at the moment so I am unable to test. I will return to you when I have found something out.

rene-neimann commented 1 year ago

Both, v1 and v2 connected-vehicle APIs work well from me from Swagger/Postman right now - doesn't seem like problem with Volvo servers (see more below).

Does this part in the error message seem relevant?

pydantic.error_wrappers.ValidationError: 2 validation errors for GetVinModel
status
field required (type=value_error.missing)
operationId
field required (type=value_error.missing)
curl --location 'https://api.volvocars.com/connected-vehicle/v2/vehicles' \
--header 'vcc-api-operationId: <string>' \
--header 'Accept: application/json' \
--header 'vcc-api-key: xxxxxxxxxxxxxxxxxxxxxxxxx' \
--header 'Authorization: Bearer xxxxxxxxxxxxxxxxxxx

{
    "data": [
        {
            "vin": "XXXXXXXXXXXXXXX"
        }
    ],
    "pagination": {
        "limit": 1,
        "total": 1,
        "offset": 0
    }
}
curl -X 'GET' \
  'https://api.volvocars.com/connected-vehicle/v1/vehicles' \
  -H 'accept: application/vnd.volvocars.api.connected-vehicle.vehiclelist.v1+json' \
  -H 'vcc-api-key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
  -H 'Authorization: Bearer xxxxxxxxxxxxxx

{
  "status": 200,
  "operationId": "2b90210d-b2ee-4543-a12b-ec7fafc592cc",
  "data": [
    {
      "vin": "XXXXXXXXXXXXXXXXXX"
    }
  ],
  "pagination": {
    "limit": 1,
    "total": 1,
    "offset": 0
  }
}
fars-fede-fire commented 1 year ago

So it seems that Volvo has changed some of the data the APIs return causing some errors. It should be fixed now in this branch: https://github.com/fars-fede-fire/volvoaaos/tree/fix-api-changes. Would you mind trying(again...)?

rene-neimann commented 1 year ago

Seems fixed, I was able to set up the integration successfully now. Enabled debug logging, reloaded integration, restarted HA - all good without any errors in logs.

What's the best practice for pull latest data from API (e.g., for battery charge)? Does the integration poll the API regularly? Or should I do it myself by reloading the integration (manually or via automation).

fars-fede-fire commented 1 year ago

Perfect! Data is polled each minute, so you do not have to do anything.