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 55 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

@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.

@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 June 22, 2025 09:19
@home-assistant home-assistant bot requested a review from gjohansson-ST June 22, 2025 09:19
Comment on lines 212 to 257
async def _mock_api_client(
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
*,
single_vin: bool = False,
api_key_failure: bool = False,
) -> None:
aioclient_mock.clear_requests()
aioclient_mock.post(
TOKEN_URL,
json=SERVER_TOKEN_RESPONSE,
)

vins = [{"vin": DEFAULT_VIN}]

if not single_vin:
vins.append({"vin": "YV10000000AAAAAAA"})

if api_key_failure:
aioclient_mock.get(
f"{_API_URL}{_API_CONNECTED_ENDPOINT}",
exc=VolvoApiException(),
)
else:
aioclient_mock.get(
f"{_API_URL}{_API_CONNECTED_ENDPOINT}",
json={
"data": vins,
},
)

vehicle_data = await async_load_fixture_as_json(hass, "vehicle", DEFAULT_MODEL)
aioclient_mock.get(
f"{_API_URL}{_API_CONNECTED_ENDPOINT}/{DEFAULT_VIN}",
json={
"data": vehicle_data,
},
)

vehicle_data = await async_load_fixture_as_json(hass, "vehicle", "xc90_petrol_2019")
aioclient_mock.get(
f"{_API_URL}{_API_CONNECTED_ENDPOINT}/YV10000000AAAAAAA",
json={
"data": vehicle_data,
},
)
Copy link
Member

Choose a reason for hiding this comment

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

Ideally we would just mock out the object like we do in the other tests to stay consistent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Code has been refactored, but now I do not have 100% coverage anymore on api.py. Line 38 is missing, but I'm not sure how to cover that. Any idea?

@home-assistant home-assistant bot marked this pull request as draft June 23, 2025 20:09
@thomasddn thomasddn marked this pull request as ready for review June 30, 2025 07:23
@home-assistant home-assistant bot requested a review from joostlek June 30, 2025 07:23
@frenck frenck requested review from Copilot and removed request for hanwg and erwindouna July 3, 2025 20:18
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a brand-new Volvo integration for Home Assistant, complete with OAuth2 config flow, update coordinators, sensor entities, and a comprehensive test suite.

  • Adds volvo integration including sensor.py, coordinator.py, config_flow.py, and application-credentials support.
  • Implements three coordinators for staggered update intervals and error handling.
  • Provides extensive pytest fixtures, tests, and snapshot files for multiple vehicle models.

Reviewed Changes

Copilot reviewed 54 out of 57 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
homeassistant/components/volvo/manifest.json Defined metadata, dependencies, codeowners, and quality scale
homeassistant/components/volvo/config_flow.py OAuth2 config flow with API key and VIN steps, plus reauth/reconfigure logic
homeassistant/components/volvo/coordinator.py Three DataUpdateCoordinator classes managing different update intervals
homeassistant/components/volvo/sensor.py Sensor entity definitions mapping API fields to HA entities
tests/components/volvo/ New tests for init, coordinator, sensor, config flow, and supporting fixtures
Comments suppressed due to low confidence (1)

tests/components/volvo/conftest.py:40

  • The full_model fixture is only parametrized with the electric model; consider adding diesel and petrol models (e.g., s90_diesel_2018, xc90_petrol_2019) to this list to ensure init and coordinator tests cover all vehicle types.
@pytest.fixture(params=[DEFAULT_MODEL])

@thomasddn
Copy link
Contributor Author

thomasddn commented Jul 4, 2025

Volvo released a new version of their energy endpoint, along with new scopes to use. While they mention the old version will still be accessible for 6 months, it appears we cannot sign in anymore with the previous scopes.

I have updated the integration to use the new endpoint version, here's a summary of what's changed:

  • sensor: Added new and changed existing sensors (with their translations and icons)
  • sensor: The new endpoint returns data that other endpoints also return, sometimes with a different name, sometimes under the same name. Therefore creating entities from the descriptions have become a little more complex. Only one entity should be created for the same value, and the preference goes to the coordinator that has the fastest interval.
  • sensor: There is one sensor, charging_power_status, which has no dedicated list of possible values documented, althoug the values I discovered so for look enum-ish: NO_POWER_AVAILABLE and PROVIDING_POWER. I just convert it to words.
  • init: Add coordinators from fastest to slowest
  • coordinator: Simplified determining which API calls are eligible for this vehicle

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.

10 participants