Skip to content

Add new Volvo integration #142994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: dev
Choose a base branch
from
Open

Conversation

thomasddn
Copy link
Contributor

@thomasddn thomasddn commented Apr 15, 2025

Proposed change

This new integration allows you to integrate your Volvo vehicle in Home Assistant.

There was already a Volvo integration, but the API used was deprecated and the integration is no longer maintained. I've chosen to make a completely new integration instead of rebuilding the existing one mainly because the deprecated integration uses the volvooncall domain. "On Call" is a reference to the marketing name of the deprecated Volvo API. This new integration uses volvo which is agnostic of any API marketing name.

Ideally, the old volvooncall integration is removed.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@thomasddn
Copy link
Contributor Author

Test is failing on an unrelated component: tests/components/esphome/test_dashboard.py

Copy link
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial review

Comment on lines +132 to +135
if self.source in (SOURCE_REAUTH, SOURCE_RECONFIGURE):
# Don't let users change the VIN. The entry should be
# recreated if they want to change the VIN.
return await self._async_create_or_update()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally I would argue that we create 1 entry for the account and just create the cars on the fly. It might even use sub entries

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is that, once all platforms have been added, a single coordinator update cycle will consume about a dozen of API requests. There is a limit on the number of API requests a user can make per API key. So I wouldn't add all vehicles on the fly, and try to keep an API key per vehicle. I can look into sub entries if that is still feasible then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've spent a few hours wrapping my head around sub entries (most of the time to already refactoring code so I could use the same flow in both root entry and sub entry, but probably was not the best choice in hindsight 😄). I'm at the point now where I can create a sub entry, but it seems that the integration init only runs for the root config entry.

I've searched in the source code for examples, and could only find kitchen_sink and mqtt, but it is still unclear to me how to assign entities to the sub entry, or let the coordinator do its work.

How can I now effectively add entities to a sub entry? I thought HA would init all sub entries automatically, as if they were a first class entry. That would take some load off of the implementors and simplify things from a implementor's perspective. Or if that is not possible, then maybe sub entries are not the best fit for this scenario?

Please advise.

@home-assistant home-assistant bot marked this pull request as draft April 15, 2025 15:29
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

#
# Raising ConfigEntryAuthFailed will cancel future updates
# and start a config flow with SOURCE_REAUTH (async_step_reauth)
_LOGGER.exception(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a rightful usage of Exception? Shouldn't this be _LOGGER.error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, tbh. Don't we want to know what exactly happened?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I contributed in some part of this checks here is my comments about this part:

this _LOGGER.exception is very usefull to understand some problems that we got from Volvo API. And that VolvoAuthCondition is one that we must understand what are the real cause.

If the Volvo servers are really trustable I agree to use only error, but we still receive strange messages from Volvo servers and this helps to understand. As an example there is an API entrypoint that sometimes return correct result and sometimes 404.

I suggest to keep this for sometime until Volvo servers return to be stable, and we dont have to understand what is happening on some of the API calls.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also know why the Volvo servers are unstable?
Generally speaking the exception is used when something truly breaks and can't continue. Is that also the case here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also know why the Volvo servers are unstable?

No, not really.

Generally speaking the exception is used when something truly breaks and can't continue. Is that also the case here?

If a VolvoAuthException is raised during the coordinator update cycle, then it means that the token refresh has failed and no data will be retrieved.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erwindouna some have tried to contact them without responses. Apparently they have many servers and depends what server responds to your request or what route you take. One time that I got timeouts using my fiber connection I was able to get responses using my starlink. For me the problem with 404 is related to some kind of reverse proxy and backend that is not correctly configured.

@thomasddn thomasddn marked this pull request as ready for review April 16, 2025 16:32
@home-assistant home-assistant bot requested review from joostlek and erwindouna April 16, 2025 16:32
@thomasddn
Copy link
Contributor Author

I've marked it ready for review again, while knowing there are still two open questions/remarks:

  1. How to handle fuel consumption unit? Keep it in an option flow, or create a new device class in core? See my comment on how other core integrations are doing it.
  2. Should I use sub entries (for cases when the user has multiple vehicles under the same Volvo account)?

Copy link
Contributor

@NoRi2909 NoRi2909 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments from me as a translator for the user-facing strings.

@NoRi2909 NoRi2909 mentioned this pull request Apr 17, 2025
19 tasks
@thomasddn thomasddn marked this pull request as draft April 19, 2025 09:04
@thomasddn thomasddn marked this pull request as ready for review April 19, 2025 15:19
@thomasddn
Copy link
Contributor Author

Pulled latest from dev and CI is failing on something unrelated (tests/components/esphome/test_manager.py).

@bohmandan
Copy link

bohmandan commented Apr 23, 2025

Fantastic work @thomasddn! Just a question regarding car models supported.
You mention in your documentation:
- All car models starting from model year 2015 (although some might have fewer features available).

But in the API documentation it says:
Car models
This API is generally, with some exceptions, available for:

All cars with Volvo On Call add-on from model year 2010-2024
All cars with Google Built In from model year 2020
(some endpoints have limited availability)

https://developer.volvocars.com/apis/connected-vehicle/v2/overview/#availability

Or am I looking in the wrong place?

@thomasddn
Copy link
Contributor Author

@bohmandan Good catch! Apparently, they have done some changes to their API and documentation recently, and they now support more vehicles. See a previous version of that page on the wayback machine.

I will adapt the docs. Thanks for bringing this to my attention!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants