Skip to content
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

Add renault integration #39605

Merged
merged 57 commits into from
Jul 28, 2021
Merged

Add renault integration #39605

merged 57 commits into from
Jul 28, 2021

Conversation

epenet
Copy link
Contributor

@epenet epenet commented Sep 3, 2020

Proposed change

Add integration for monitoring Renault vehicles, to replace custom_component.

Initial PR implements config_flow, with sensor platform.
Follow-up PRs will include device_tracker and services

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)
  • 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
  • The code has been formatted using Black (black --fast 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.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

Copy link
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

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

Hi there @epenet!

I've quickly viewed your PR and left some comments to resolve before we can continue the review process. Looking forward to this! 👍

.coveragerc Outdated Show resolved Hide resolved
homeassistant/components/renault/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/renault/pyzeproxy.py Outdated Show resolved Hide resolved
@frenck
Copy link
Member

frenck commented Sep 3, 2020

Please do not squash the commits, it makes it very hard to review/track progress. We will squash the PR into a single commit on merge.

@epenet
Copy link
Contributor Author

epenet commented Sep 3, 2020

Please do not squash the commits, it makes it very hard to review/track progress. We will squash the PR into a single commit on merge.

I've removed the extra sensors, and the fetching of the API keys.
Promise: future commits won't be squashed.

Copy link
Member

@Quentame Quentame left a comment

Choose a reason for hiding this comment

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

Did not look at config_flow

homeassistant/components/renault/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/renault/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/renault/pyzeproxy.py Outdated Show resolved Hide resolved
homeassistant/components/renault/pyzeproxy.py Outdated Show resolved Hide resolved
homeassistant/components/renault/pyzevehicleproxy.py Outdated Show resolved Hide resolved
homeassistant/components/renault/sensor.py Outdated Show resolved Hide resolved
homeassistant/components/renault/pyzevehicleproxy.py Outdated Show resolved Hide resolved
homeassistant/components/renault/pyzeproxy.py Outdated Show resolved Hide resolved
homeassistant/components/renault/const.py Outdated Show resolved Hide resolved
homeassistant/components/renault/config_flow.py Outdated Show resolved Hide resolved
@epenet
Copy link
Contributor Author

epenet commented Oct 25, 2020

Thanks @Quentame. I'll work on those changes - but it looks like more work is required on the underlying PyZE library...

@epenet
Copy link
Contributor Author

epenet commented Oct 31, 2020

Thanks @Quentame, I've worked through your review.

@epenet epenet marked this pull request as draft November 12, 2020 13:28
@epenet epenet changed the title Add renault integration Draft: Add renault integration Nov 12, 2020
@epenet
Copy link
Contributor Author

epenet commented Jul 27, 2021

Rebased due to conflicting files:

  • .strict-typing
  • mypy.ini

Copy link
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

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

✅ I think this looks nice! Considering the size of this PR, I would like to see a second approval from another reviewer though.

Adding a label for that.

@frenck frenck added almost-done second-opinion-wanted Add this label when a reviewer needs a second opinion from another member. labels Jul 27, 2021
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes of this entity."""
last_update = self.data.timestamp if self.data else None
return {ATTR_LAST_UPDATE: last_update}
Copy link
Member

Choose a reason for hiding this comment

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

Why is this necessary? States already have last_changed and last_updated attributes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@balloob this is the last time that the Renault vehicle talked to the Renault servers. It is part of the response from the Renault API.
It serves to highlight issues where the HA component is working normally, the Renault servers are working correctly, but the car itself has stopped sending updates.

@balloob balloob merged commit 8d84edd into home-assistant:dev Jul 28, 2021
@balloob balloob removed the second-opinion-wanted Add this label when a reviewer needs a second opinion from another member. label Jul 28, 2021
frenck pushed a commit that referenced this pull request Jul 28, 2021
Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Please address the comments in a new PR. Thanks!


def __init__(self, hass: HomeAssistant, locale: str) -> None:
"""Initialise proxy."""
LOGGER.debug("Creating RenaultHub")
Copy link
Member

Choose a reason for hiding this comment

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

We don't want side effects in init methods. Please move or remove the logging.

# Generate vehicle proxy
vehicle = RenaultVehicleProxy(
hass=self._hass,
vehicle=await self._account.get_api_vehicle(vehicle_link.vin),
Copy link
Member

Choose a reason for hiding this comment

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

Does the vehicle initialization need to be done in sequence or can we use asyncio.gather to do it concurrently?

coordinator = self.coordinators[key]
if coordinator.not_supported:
# Remove endpoint as it is not supported for this vehicle.
LOGGER.error(
Copy link
Member

Choose a reason for hiding this comment

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

Looks like warning may be more appropriate?

return entities


async def get_vehicle_entities(vehicle: RenaultVehicleProxy) -> list[RenaultDataEntity]:
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't need to be a coroutine function since we don't await inside.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I move up the list, I still end up with async def async_setup_entry
Is there a non-async version of this method?

Copy link
Member

Choose a reason for hiding this comment

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

No, that function is part of the API, so we can't change that one.

return self.data.batteryLevel if self.data else None

@property
def icon(self) -> str:
Copy link
Member

Choose a reason for hiding this comment

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

This isn't needed when setting device class. It's already handled by the frontend. Please remove it.

# them to be.
assert await async_setup_entry(hass, config_entry)
assert DOMAIN in hass.data and config_entry.unique_id in hass.data[DOMAIN]
assert isinstance(hass.data[DOMAIN][config_entry.unique_id], RenaultHub)
Copy link
Member

Choose a reason for hiding this comment

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

We want to avoid asserting integration details like the contents of hass.data. Assert the state of the config entry instead.

assert DOMAIN in hass.data and config_entry.unique_id in hass.data[DOMAIN]
assert isinstance(hass.data[DOMAIN][config_entry.unique_id], RenaultHub)

renault_hub: RenaultHub = hass.data[DOMAIN][config_entry.unique_id]
Copy link
Member

Choose a reason for hiding this comment

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

Please don't access integration details in the tests. Patch the library and assert the calls made to the mock.

)

# Unload the entry and verify that the data has been removed
assert await async_unload_entry(hass, config_entry)
Copy link
Member

Choose a reason for hiding this comment

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

Please use hass.config_entries.async_unload instead.

with patch(
"renault_api.renault_session.RenaultSession.login",
side_effect=aiohttp.ClientConnectionError,
), pytest.raises(ConfigEntryNotReady):
Copy link
Member

Choose a reason for hiding this comment

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

Assert the state of the config entry instead.

vehicle_proxy = await create_vehicle_proxy(hass, vehicle_type)

with patch(
"homeassistant.components.renault.RenaultHub.vehicles",
Copy link
Member

Choose a reason for hiding this comment

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

Please patch the library instead.

@epenet epenet deleted the renault branch July 29, 2021 07:00
@epenet
Copy link
Contributor Author

epenet commented Jul 29, 2021

Thanks @frenck / @balloob

I will now start work on the comments from @MartinHjelmare

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