Skip to content

Default device name to config entry title#95547

Merged
balloob merged 3 commits into
devfrom
default-device-name
Jun 30, 2023
Merged

Default device name to config entry title#95547
balloob merged 3 commits into
devfrom
default-device-name

Conversation

@balloob
Copy link
Copy Markdown
Member

@balloob balloob commented Jun 29, 2023

Breaking change

Proposed change

If no device name is given, we default the name of the device to the config entry title. This is ignored if a default name is given. That way we always have a device name.

Replaces #95485

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
  • I have followed the perfect PR recommendations
  • 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:

@balloob balloob requested a review from a team as a code owner June 29, 2023 13:03
@balloob balloob added this to the 2023.7.0 milestone Jun 29, 2023
@joostlek
Copy link
Copy Markdown
Member

(first time reviewing core stuff, don't know all the details yet)

In the previous PR you were questioning if devices should be allowed to have no name.

  1. Wouldn't it be better if this happened on device level? (Although I don't know if the device has access to the config entry)

  2. Make name mandatory and set default values in integrations.

Not sure if these are viable options, but I think they sound more logical.

In any way, wouldn't a log message be useful to let people know they are running an integration with a device without a name? (Same way like we now have with _attr_name = None) So we avoid integrations using the config entry name implicitly.

@balloob balloob removed this from the 2023.7.0 milestone Jun 29, 2023
@balloob
Copy link
Copy Markdown
Member Author

balloob commented Jun 29, 2023

Removing this from the milestone as it needs updates to a lot of integrations.

@joostlek entity platform is where an entity is added to the device registry. It seems like the right place to enforce defaults and it's already responsible for others too.

"default_name" not in processed_dev_info
and not processed_dev_info.get("name")
):
processed_dev_info["name"] = self.config_entry.title
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What if the title is an empty string? Do we need a default for that?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, it shouldn't be allowed. The goal is that we always have a device name.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it an idea to only require this when has_entity_name is True?

@balloob balloob requested a review from a team as a code owner June 29, 2023 15:32
@balloob balloob force-pushed the default-device-name branch from 3952fd4 to 592e297 Compare June 29, 2023 17:27
@balloob balloob merged commit 9280dc6 into dev Jun 30, 2023
@balloob balloob deleted the default-device-name branch June 30, 2023 17:54
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 1, 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.

4 participants