HomeMatic: Enable entity registry#15950
HomeMatic: Enable entity registry#15950MartinHjelmare merged 3 commits intohome-assistant:devfrom danielperna84:homematic_entity_registry
Conversation
|
Is it possible to check if a friendly name is used instead of a unique name? We shouldn't return a name that is not unique, ever. That's against the rules for |
| @property | ||
| def unique_id(self): | ||
| """Return unique ID. HomeMatic entity IDs are unique by default.""" | ||
| return self._name |
There was a problem hiding this comment.
Please clarify if the user can make this non unique or if this will always be constant (unique). Reading this PR description and the linked issue, it's not clear to me what you mean might change due to setting friendly name (using the resolve names function).
There was a problem hiding this comment.
As long as the unique_id is unique and doesn't change for an entity, the entity_id for that entity will not change during restarts, even if later another entity_id is suggested (eg by the user in device app).
That's the whole point of the entity registry. The entity registry is the truth for the entity_ids. So after an entity has been registered, the entity_id can only be changed via the entity registry or an api that uses the entity registry.
I'm not sure if it's possible to pass on that bit of information easily. There's an option for the component called
By default the entity IDs of HomeMatic entities look like this: Later today I will try how it works if I manually set the unique ID to always be the same value as when no friendly names are being resolved. I tried that yesterday and has some trouble with that. But I did it in a stupid way. Maybe the one I got on my midn now works better. |
|
Ok, so I changed the code to this: @property
def unique_id(self):
"""Return unique ID. HomeMatic entity IDs are unique by default."""
if self._state:
return "{}_{}_{}".format(self._address, self._channel, self._state)
return "{}_{}".format(self._address, self._channel)But this gives me the same strange behavior as yesterday. Don't know if this also could be a bug in the registry. Here's what happens:
climate.abc123456:
config_entry_id:
name:
platform: homematic
unique_id: ABC123456_1
climate.abc123456:
config_entry_id:
name:
platform: homematic
unique_id: ABC123456_1_SET_TEMPERATURE
climate.mynewentityid:
config_entry_id:
name: myfriendlyname
platform: homematic
unique_id: ABC123456_1
With the solution I so far have in this PR the changes become active instantly and I don't get 2 entries. The second entry I get with this new approach is what's making me scratch my head, since it doesn't show up in the dev-panel. So it looks like an intermediate entity that was created by the registry-code. If it helps: the prepended This second approach definitely is not functional, althouth in theory this would mitigate the issues with the uncertain entity IDs the component creates when it uses the names from the hub. |
|
I changed the code now to look at the name, and only if it (still) includes the serial number, then the unique ID is generated. Assuming people don't include the serial in the friendly name they have set up on the hub (which is highly probable since that's why they change the name in the first place), this will exclude those users from the entity registry, and therefore the requirement of static uniqe IDs is met. This means that people who want to use the registry have to disable the component-feature (resolving names). So it's kind of opt-in for them, and enabled by default for the others. Is this an acceptable solution? I'll see if I can come up with a helper-script ran manually by HomeMatic users that makes it easy to transition from a setup with resolved names to the regular mode. |
There was a problem hiding this comment.
That was a long time on my task list. But it is not so easy like this PR :) Would be nice if you can finish it:
_create_ha_nameshould be ->_create_ha_unique(or so?) and use the address instead name to generate a unique ID. Name should be work like before, se we should be able to reuse this function, for unique ID we call it with address and for name we call it with name like now.
|
I feel sooooo stupid! Works great, even with |
|
@danielperna84 I think I'm missing a documentation PR for this one? |
|
@frenck |
|
@danielperna84 |
|
Yeah, we don't track entity registry support consistently at the moment. If someone adds the framework for that we can start doing it. |
* Set unique ID * Excluding setups that resolve names * Added support for resolvenames again
* Set unique ID * Excluding setups that resolve names * Added support for resolvenames again
Description:
Enabeling support for the entity registry. The entity IDs the HomeMatic component creates by default are uniqe and for every device always the same entity will be generated. This also works when the option to generate userfriendly entity IDs is being used. The entity ID can change though when using the userfriendly names (when the friendly name is changed in the hub-device). This will generate an entry in the registry that becomes stale.
The clean approach would be to disable the possibility the generate userfriendly names altogether. But as far as I know quite a few users are using this option, and removing support for that would break these configurations fundamentally. The way it is implemented looks acceptable to me since only a subset of the HomeMatic users would be affected by stale entries.
Checklist:
tox. Your PR cannot be merged unless tests pass