-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
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
base: dev
Are you sure you want to change the base?
Add new Volvo integration #142994
Conversation
Test is failing on an unrelated component: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initial review
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
I've marked it ready for review again, while knowing there are still two open questions/remarks:
|
There was a problem hiding this 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.
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, | ||
}, | ||
) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
Month is not a supported value for the `DURATION` device class
There was a problem hiding this 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 includingsensor.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])
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:
|
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 usesvolvo
which is agnostic of any API marketing name.Ideally, the old
volvooncall
integration is removed.Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
.To help with the load of incoming pull requests: