Device registry store config entry#16152
Conversation
There was a problem hiding this comment.
Trigger save if it didn't contain the config entry.
There was a problem hiding this comment.
Shouldn't identifiers and connection also be sets of tuples?
set([ ('mac', 'aa:bb'), ('deconz', 123) ])
There was a problem hiding this comment.
Yes, lets do it properly now :)
|
Renaming and retyping has made device parameters a lot clearer. 👍 |
There was a problem hiding this comment.
I think default should be a function, not a set?
There was a problem hiding this comment.
Im not following, this works as expected for an attribute that might not be set on creation.
What should the function solve @balloob ?
There was a problem hiding this comment.
The set will be shared between all instances? See the 2nd code snippet in the docs. You need to do factory=set instead.
There was a problem hiding this comment.
Maybe it's working in this case because the empty set is passed into converter, which will construct a new set.
There was a problem hiding this comment.
We should only save if the device has changed.
There was a problem hiding this comment.
for the sake of giving good examples, we should not use bridgeid here. All identifiers need to be scoped and not be generic names. If Hue and Deconz use same bridge ids, it shouldn't match devices.
There was a problem hiding this comment.
That is improved by the deconz device registry PR. I prefer to not duplicate implementation between two different PRs.
There was a problem hiding this comment.
Let's make config entry mandatory (not default to None). Otherwise we don't know when to clean up devices etc. Now it's easy as on removal of a config entry we can delete things.
There was a problem hiding this comment.
Cleaning up devices on removal of a config entry is for another PR btw ;)
There was a problem hiding this comment.
What about devices not having a config entry?
There was a problem hiding this comment.
I've been starting to look at removing devices in a separate PR 👍
There was a problem hiding this comment.
dictionary key 'config_entries' repeated with different values
There was a problem hiding this comment.
dictionary key 'config_entries' repeated with different values
c9882fa to
2f34d27
Compare
| name=device.get('name'), | ||
| sw_version=device.get('sw_version')) | ||
| config_entry=config_entry_id, | ||
| connections=device_info['connections'], |
There was a problem hiding this comment.
This will blow up if the key connections, identifiers or manufacturer does not exist. We should use device_info.get('connections', []).
We should probably be defensive for all values and use get
There was a problem hiding this comment.
Yes, we already have an issue report on this it seems :)
| self.async_schedule_save() | ||
| return device | ||
|
|
||
| device = DeviceEntry( |
There was a problem hiding this comment.
We should not create a new device if it has no connections or identifiers, as it can never be retrieved again
There was a problem hiding this comment.
Should identifiers be mandatory or should it check and fail for any of them?
There was a problem hiding this comment.
I guess you're right that at least one is mandatory, I am fine with ignoring it when it doesn't match and just print a warning
balloob
left a comment
There was a problem hiding this comment.
Ok to merge when added that we don't save when we have no connection or identifier
|
@balloob isn't the top if statement doing just that? If someone else triggers save later it will still be stored |
* Allow device registry to optionally store config entries * Connections and identifiers are now sets with tupels * Make config entries mandatory * Fix duplicate keys in test * Rename device to device_info * Entity platform should only create device entries if config_entry_id exists * Fix Soundtouch tests * Revert soundtouch to use self.device * Fix baloobs comments * Correct type in test
Description:
Related issue (if applicable): fixes #16183
Checklist:
tox. Your PR cannot be merged unless tests passIf the code does not interact with devices: