-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
Keep the provided name when creating a tag #128240
Conversation
Hey there @balloob, @dmulcahey, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
Is there a bug in this test then? https://github.com/home-assistant/core/blob/dev/tests/components/tag/test_init.py#L269 |
No, the (websocket) handler works correctly, what is being tested in this test, what is also being mentioned in both issues. There's a bug in the attached listener. |
Isn't that test case what's happening when creating a tag (as mentioned in the issue)? |
It doesn't because the provided name is taken in consideration. Shortly after, it is "removed" in the attached listeners by not passing in the name. Steps:
|
I think we should update the diff --git a/homeassistant/components/tag/__init__.py b/homeassistant/components/tag/__init__.py
index 0462c5bec3..95efae3d38 100644
--- a/homeassistant/components/tag/__init__.py
+++ b/homeassistant/components/tag/__init__.py
@@ -84,7 +84,9 @@ def _create_entry(
original_name=f"{DEFAULT_NAME} {tag_id}",
suggested_object_id=slugify(name) if name else tag_id,
)
- return entity_registry.async_update_entity(entry.entity_id, name=name)
+ if name:
+ return entity_registry.async_update_entity(entry.entity_id, name=name)
+ return entry
class TagStore(Store[collection.SerializedStorageCollection]):
diff --git a/tests/components/tag/test_init.py b/tests/components/tag/test_init.py
index 6f309391d2..5c1e80c2d8 100644
--- a/tests/components/tag/test_init.py
+++ b/tests/components/tag/test_init.py
@@ -294,6 +294,10 @@ async def test_entity_created_and_removed(
assert item["id"] == "1234567890"
assert item["name"] == "Kitchen tag"
+ await hass.async_block_till_done()
+ er_entity = entity_registry.async_get("tag.kitchen_tag")
+ assert er_entity.name == "Kitchen tag"
+
entity = hass.states.get("tag.kitchen_tag")
assert entity
assert entity.state == STATE_UNKNOWN |
I've applied your changes since they make sense.
I'm not sure if I still have to do something for this.
It is also run upon restarting, which may update the entity_registry unneccessary. |
I noticed that also when I looked at it so I think it should be looked at but it's slightly out of scope for this PR which is for solving the name bug. |
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Co-authored-by: G Johansson <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @silamon 👍
All test failures are not related to this PR.
* Keep the name * Add patch * Update homeassistant/components/tag/__init__.py Co-authored-by: G Johansson <[email protected]> --------- Co-authored-by: G Johansson <[email protected]>
Proposed change
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
.To help with the load of incoming pull requests: