-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
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 overkiz unique ids stable for pyoverkiz >= 1.10.1 #99765
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,7 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"""Parent class for every Overkiz device.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from __future__ import annotations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from enum import StrEnum | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from typing import cast | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from pyoverkiz.enums import OverkizAttribute, OverkizState | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -114,7 +115,12 @@ def __init__( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"""Initialize the device.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
super().__init__(device_url, coordinator) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.entity_description = description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self._attr_unique_id = f"{super().unique_id}-{self.entity_description.key}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Keep ids stable for pyoverkiz >= 1.10.1 where enums changed to StrEnum. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
unique_id_ext = self.entity_description.key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if isinstance(unique_id_ext, StrEnum): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
unique_id_ext = f"{unique_id_ext.__class__.__name__}.{unique_id_ext.name}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self._attr_unique_id = f"{super().unique_id}-{unique_id_ext}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+120
to
+123
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of this, can we rewrite unique IDs via a migration step? Here's an example of how it can be done: core/homeassistant/components/bmw_connected_drive/__init__.py Lines 82 to 110 in 714fc53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On second thought, this may be very tricky to get 100% correct, rewriting the unique_id as suggested in this PR is fine. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @emontnemery it sucks that we didn't catch this before Python 3.11 was added to HA (no tests in Overkiz is the main cause). The Python3.11 update had a breaking change in how (str, Enum) are handled. See https://blog.pecar.me/python-enum. History: So by not catching it, we actually broke the entity registry multiple times for our users. This happens to entities that I am not actively using myself, thus I didn't spot it earlier. Would be good to fix it now once and for all and move back to the original unique id. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. First try to implement your suggestion: #101024. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if self.is_sub_device: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# In case of sub device, use the provided label | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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.
I think the comment is wrong, shouldn't it be like this?
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.
You're right. This needs to be
1.10.0
here and in the commit message. There's a chance that github would lose the discussion below if I change the commit in the PR. I'd therefore only do that in a later step if we go on with this PR.