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

Fix invalid unique id for Transmission entities #84664

Merged
merged 13 commits into from Jun 28, 2023

Conversation

avee87
Copy link
Contributor

@avee87 avee87 commented Dec 27, 2022

Proposed change

Currently it's using host and entity name for unique id which is not acceptable. Changing to config entry id + key.

Follow up PR will enable new entity naming and use entity descriptions - I don't want to do all this in one PR because it would do too many things at once and get stuck. See #74438 which I'm splitting into smaller parts now.

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

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

To help with the load of incoming pull requests:

@home-assistant
Copy link

Hey there @engrbm87, @JPHutchins, mind taking a look at this pull request as it has been labeled with an integration (transmission) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of transmission can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Change the title of the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign transmission Removes the current integration label and assignees on the issue, add the integration domain after the command.

tests/components/transmission/test_init.py Outdated Show resolved Hide resolved
tests/components/transmission/test_init.py Outdated Show resolved Hide resolved
Copy link
Contributor

@engrbm87 engrbm87 left a comment

Choose a reason for hiding this comment

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

Few suggestions for the migration test. Also let's add type hints for new code.

tests/components/transmission/test_init.py Outdated Show resolved Hide resolved
tests/components/transmission/test_init.py Outdated Show resolved Hide resolved
@avee87 avee87 mentioned this pull request Apr 26, 2023
20 tasks
tests/components/transmission/test_init.py Outdated Show resolved Hide resolved
tests/components/transmission/test_init.py Outdated Show resolved Hide resolved
tests/components/transmission/test_init.py Outdated Show resolved Hide resolved
tests/components/transmission/test_init.py Outdated Show resolved Hide resolved
homeassistant/components/transmission/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/transmission/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/transmission/__init__.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft April 28, 2023 09:34
@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.

@avee87 avee87 marked this pull request as ready for review April 28, 2023 10:10
@avee87
Copy link
Contributor Author

avee87 commented Apr 28, 2023

Coverage issue is now gone! Thank you @epenet

tests/components/transmission/test_init.py Outdated Show resolved Hide resolved
tests/components/transmission/test_init.py Outdated Show resolved Hide resolved
tests/components/transmission/test_init.py Outdated Show resolved Hide resolved
tests/components/transmission/test_init.py Outdated Show resolved Hide resolved
tests/components/transmission/test_init.py Outdated Show resolved Hide resolved
homeassistant/components/transmission/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/transmission/__init__.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft April 28, 2023 11:30
@epenet epenet changed the title Update unique id for Transmission entities Fix invalid unique id for Transmission entities Apr 28, 2023
@avee87 avee87 marked this pull request as ready for review April 28, 2023 11:51
@avee87 avee87 requested a review from epenet April 28, 2023 11:51
Copy link
Contributor

@epenet epenet left a comment

Choose a reason for hiding this comment

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

One more little tweak, to account for @engrbm87 comment regarding cases that can't happen, and then I think it's good.

tests/components/transmission/test_init.py Outdated Show resolved Hide resolved
tests/components/transmission/test_init.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft April 28, 2023 11:52
@avee87
Copy link
Contributor Author

avee87 commented Apr 28, 2023

I had those cases as an attempt to improve code coverage. They are not relevant now so will remove.

@avee87 avee87 marked this pull request as ready for review April 28, 2023 12:06
@avee87 avee87 requested a review from epenet April 28, 2023 12:06
Copy link
Contributor

@epenet epenet left a comment

Choose a reason for hiding this comment

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

LGTM 👍
It would be nice to have confirmation from a code owner

@avee87
Copy link
Contributor Author

avee87 commented May 4, 2023

@engrbm87, @JPHutchins, any thoughts on this?

@frenck frenck added the smash Indicator this PR is close to finish for merging or closing label Jun 21, 2023
Copy link
Contributor

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

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

The unique_id cleanup is fine as such, but we should not add deprecated composing of names.
Background in https://developers.home-assistant.io/docs/core/entity#has_entity_name-true-mandatory-for-new-integrations

self._client_name = client_name
self._name = sensor_name
self._sub_type = sub_type
self._attr_name = f"{client_name} {sensor_name}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't add this unwanted composing of name with device name.
Instead, leave it as is and in another PR set _attr_has_entity_name = True to have the name composing happen automatically in frontend.

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 adding name composing, I'm keeping existing functionality just moving it from function to attribute.

I've been explicitly asked to avoid doing too many things in one PR so this one is focused on unique_id. Once it's merged I'll be happy to migrate to new entity naming.

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right, sorry about that!
A PR setting _attr_has_entity_name = True would still be welcome 👍

@home-assistant home-assistant bot marked this pull request as draft June 28, 2023 07:43
@frenck frenck removed the smash Indicator this PR is close to finish for merging or closing label Jun 28, 2023
@avee87 avee87 marked this pull request as ready for review June 28, 2023 08:16
@avee87 avee87 requested a review from emontnemery June 28, 2023 08:17
Copy link
Contributor

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

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

Thanks, @avee87 👍

@emontnemery emontnemery merged commit a5b91cb into home-assistant:dev Jun 28, 2023
24 checks passed
@avee87 avee87 deleted the transmission_unique_id branch June 28, 2023 10:52
@github-actions github-actions bot locked and limited conversation to collaborators Jun 29, 2023
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.

None yet

6 participants