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

Use EntityDescription - renault #55061

Merged
merged 12 commits into from
Aug 25, 2021

Conversation

epenet
Copy link
Contributor

@epenet epenet commented Aug 23, 2021

Proposed change

Update renault to use EntityDescription for entity metadata, and add state class for sensors.
-> #53201

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

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

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.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • 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:

@frenck frenck added the smash Indicator this PR is close to finish for merging or closing label Aug 23, 2021
@frenck frenck removed the smash Indicator this PR is close to finish for merging or closing label Aug 24, 2021
Copy link
Member

@cdce8p cdce8p left a comment

Choose a reason for hiding this comment

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

Just left some last formatting comments.

Aside from that, the overall structure LGTM. The details are a bit more difficult to review, especially since this is such a large PR. I trust that you tested it there.

@cdce8p cdce8p added the smash Indicator this PR is close to finish for merging or closing label Aug 24, 2021
@epenet
Copy link
Contributor Author

epenet commented Aug 24, 2021

Thanks @cdce8p I've fixed the formatting issue on my machine.
I'm just trying to sort out some value_lambda before I ask for a final validation.

@epenet epenet requested a review from cdce8p August 24, 2021 16:26
@epenet
Copy link
Contributor Author

epenet commented Aug 24, 2021

@cdce8p would you mind taking a final look now that the value_lambda is in?

Copy link
Member

@cdce8p cdce8p left a comment

Choose a reason for hiding this comment

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

@epenet The last changes LGTM, too!

@epenet
Copy link
Contributor Author

epenet commented Aug 25, 2021

Great, thanks @cdce8p
Regarding testing - I've done thorough checks on my end, and improved test coverage to include extra attributes (icon, state-class and last-update)
Now the test are failing due to #55169

@frenck frenck force-pushed the renault-entity-description branch from 609d20f to fcc192b Compare August 25, 2021 07:04
@frenck
Copy link
Member

frenck commented Aug 25, 2021

Rebased the PR to deal with the CI issues

@frenck frenck requested a review from cdce8p August 25, 2021 08:57
@epenet
Copy link
Contributor Author

epenet commented Aug 25, 2021

If it reassures the team, I can split the "test" amends into a preliminary PR to show that functionnality hasn't been impacted at all by the release, and move the "state-class" amends into a subsequent PR afterwards...

@cdce8p cdce8p added project-code_style PRs related to #53201 - pylint CodeStyle update and removed smash Indicator this PR is close to finish for merging or closing labels Aug 25, 2021
@cdce8p cdce8p marked this pull request as draft August 25, 2021 20:49
Copy link
Member

@cdce8p cdce8p left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! Unfortunately we missed the window for 2021.09. Since this is a larger refactoring, I would like to wait until after the release (in a week) before merging it.

Marked the PR as draft to indicate that.

@epenet
Copy link
Contributor Author

epenet commented Aug 25, 2021

aarrgh so close... ;)
I may need to rebase again if #54745 and/or #54820 get merged (to finish the migration from HACS custom_component).
Is it useful for me to get the intermediate "test" amends in a preliminary PR?

@cdce8p
Copy link
Member

cdce8p commented Aug 25, 2021

aarrgh so close... ;)
I may need to rebase again if #54745 and/or #54820 get merged (to finish the migration from HACS custom_component).
Is it useful for me to get the intermediate "test" amends in a preliminary PR?

Wasn't aware of that. We had a small discussion on discord how to handle PRs with large refactorings shortly before the release. Turns out I was overly worried 🤷🏻‍♂️ Will merge it now. That should make things easier on your end.

@cdce8p cdce8p marked this pull request as ready for review August 25, 2021 21:13
@cdce8p cdce8p merged commit 9315f3b into home-assistant:dev Aug 25, 2021
@epenet epenet deleted the renault-entity-description branch August 25, 2021 21:16
@epenet
Copy link
Contributor Author

epenet commented Aug 25, 2021

Thanks @cdce8p, thanks @frenck

if self.coordinator.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.

We don't include the item at all in the state attributes if the value is None.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @MartinHjelmare you told me the opposite on the original integration: an attribute should never "disappear".
So the way it is implemented is that sensor with battery coordinator will always have the attribute (sometimes with value, and sometimes None) and other coordinators do not return any attributes return None.

Copy link
Member

Choose a reason for hiding this comment

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

Do you have a link to that discussion?

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 can't find it. I guess I was mistaken. I'll implement...

data_key="chargingStatus",
device_class=DEVICE_CLASS_CHARGE_STATE,
entity_class=RenaultSensor[KamereonVehicleBatteryStatusData],
icon_lambda=lambda x: (
Copy link
Member

Choose a reason for hiding this comment

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

For long expressions it's nicer to define a regular function and assign it here. It doesn't have to be a lambda.

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'll start work on that

state = hass.states.get(entity_id)
assert state.state == STATE_OFF
for attr in CHECK_ATTRIBUTES:
if attr == ATTR_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.

We want to avoid if/else logic in tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was this OK in sensor.py?
https://github.com/home-assistant/core/blob/dev/tests/components/renault/test_sensor.py#L34-L48

const.py and the fixtures have all the values for when things are OK.
I wanted to avoid having to put in const.py the "error" values.

Copy link
Member

Choose a reason for hiding this comment

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

I don't like that assertion helper. Generally I try to avoid assertion helpers since I think they make it harder to read the test and see what the test is testing. My preference is to have all the setup code including mocking and patching in pytest fixtures but have the function call that is tested and assertions in the test body itself.

But regardless we should keep tests as simple as possible without branching logic as far as possible.

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'll work out a better split between fixed and dynamic attributes

@github-actions github-actions bot locked and limited conversation to collaborators Aug 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants