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

Allow overriding name via entity registry #12292

Merged
merged 2 commits into from
Feb 11, 2018
Merged

Allow overriding name via entity registry #12292

merged 2 commits into from
Feb 11, 2018

Conversation

balloob
Copy link
Member

@balloob balloob commented Feb 11, 2018

Description:

This allows overriding the name of an entity via the entity registry.

If a name is defined in the entity registry, it is always used in favor of the name supplied by the device.

Define name by adding a name value under an entry in entity_registry.yaml.

Checklist:

  • The code change is tested and works locally.

If user exposed functionality or configuration variables are added/changed:

If the code does not interact with devices:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • Tests have been added to verify that the new code works.

@@ -61,6 +61,7 @@
'chardet==3.0.4',
'astral==1.5',
'certifi>=2017.4.17',
'attrs==17.4.0',
Copy link
Member Author

Choose a reason for hiding this comment

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

This introduces attrs to the codebase as per home-assistant/architecture#4

domain = attr.ib(type=str, default=None, init=False, repr=False)

def __attrs_post_init__(self):
"""Computed properties."""
Copy link
Member

Choose a reason for hiding this comment

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

Do these behave as properties or instance attributes, ie write protected or not?

Copy link
Member Author

Choose a reason for hiding this comment

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

They are write protected because the class is annotated with frozen=True. The class is frozen after the post_init has run. It allows me to operate on the values entered before it's frozen.

you have to read the 2 methods from attr as attrib and attrs btw. Makes it easier to remember

@balloob balloob merged commit 17e5740 into dev Feb 11, 2018
@balloob balloob deleted the entity-registry-name branch February 11, 2018 17:16
@arsaboo
Copy link
Contributor

arsaboo commented Feb 11, 2018

Will this also fix something like #12287 ?

@balloob balloob added this to the 0.63.1 milestone Feb 12, 2018
balloob added a commit that referenced this pull request Feb 12, 2018
* Allow overriding name via entity registry

* Update requirements
@balloob balloob mentioned this pull request Feb 12, 2018
@balloob
Copy link
Member Author

balloob commented Feb 12, 2018

Included this in 0.63.1 because another PR had a test that used something from this PR and can't be bothered to split it up.

@OttoWinter
Copy link
Member

Do I understand this correctly: The final friendly name of an entity is now determined by these things with decreasing priority:

  1. customize: in config (https://home-assistant.io/docs/configuration/customizing-devices/)
  2. entity registry (from this PR)
  3. name supplied by entity via https://github.com/home-assistant/home-assistant/blob/034eb9ae1aa33cec829393f409343919c036044c/homeassistant/helpers/entity.py#L100-L102

?

@balloob
Copy link
Member Author

balloob commented Feb 12, 2018

Correct, as it always should have been.

@home-assistant home-assistant locked and limited conversation to collaborators May 29, 2018
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.

6 participants