Skip to content

Device registry store config entry#16152

Merged
balloob merged 10 commits intohome-assistant:devfrom
Kane610:device-registry-store-config-entry
Aug 25, 2018
Merged

Device registry store config entry#16152
balloob merged 10 commits intohome-assistant:devfrom
Kane610:device-registry-store-config-entry

Conversation

@Kane610
Copy link
Copy Markdown
Member

@Kane610 Kane610 commented Aug 23, 2018

Description:

Related issue (if applicable): fixes #16183

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

@Kane610 Kane610 requested a review from a team as a code owner August 23, 2018 18:56
@ghost ghost assigned Kane610 Aug 23, 2018
@ghost ghost added the in progress label Aug 23, 2018
Copy link
Copy Markdown
Member

@balloob balloob Aug 23, 2018

Choose a reason for hiding this comment

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

Trigger save if it didn't contain the config entry.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't identifiers and connection also be sets of tuples?

set([ ('mac', 'aa:bb'), ('deconz', 123) ])

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, lets do it properly now :)

@MartinHjelmare
Copy link
Copy Markdown
Member

Renaming and retyping has made device parameters a lot clearer. 👍

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think default should be a function, not a set?

Copy link
Copy Markdown
Member Author

@Kane610 Kane610 Aug 24, 2018

Choose a reason for hiding this comment

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

Im not following, this works as expected for an attribute that might not be set on creation.

What should the function solve @balloob ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The set will be shared between all instances? See the 2nd code snippet in the docs. You need to do factory=set instead.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe it's working in this case because the empty set is passed into converter, which will construct a new set.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I will add a factory

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should only save if the device has changed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Allright

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

@Kane610 Kane610 Aug 24, 2018

Choose a reason for hiding this comment

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

That is improved by the deconz device registry PR. I prefer to not duplicate implementation between two different PRs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ok

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cleaning up devices on removal of a config entry is for another PR btw ;)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

What about devices not having a config entry?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've been starting to look at removing devices in a separate PR 👍

@balloob balloob added this to the 0.77 milestone Aug 24, 2018
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

dictionary key 'config_entries' repeated with different values

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

dictionary key 'config_entries' repeated with different values

@Kane610 Kane610 changed the title Allow device registry to optionally store config entries Device registry require config entries Aug 24, 2018
@Kane610 Kane610 changed the title Device registry require config entries Device registry store config entry Aug 24, 2018
@Kane610 Kane610 force-pushed the device-registry-store-config-entry branch from c9882fa to 2f34d27 Compare August 24, 2018 18:22
name=device.get('name'),
sw_version=device.get('sw_version'))
config_entry=config_entry_id,
connections=device_info['connections'],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, we already have an issue report on this it seems :)

self.async_schedule_save()
return device

device = DeviceEntry(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should not create a new device if it has no connections or identifiers, as it can never be retrieved again

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Should identifiers be mandatory or should it check and fail for any of them?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

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

Ok to merge when added that we don't save when we have no connection or identifier

@Kane610
Copy link
Copy Markdown
Member Author

Kane610 commented Aug 25, 2018

@balloob isn't the top if statement doing just that? If someone else triggers save later it will still be stored

@balloob balloob merged commit 97173f4 into home-assistant:dev Aug 25, 2018
@ghost ghost removed the in progress label Aug 25, 2018
balloob pushed a commit that referenced this pull request Aug 25, 2018
* 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
@Kane610 Kane610 deleted the device-registry-store-config-entry branch August 29, 2018 08:30
@balloob balloob mentioned this pull request Aug 29, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Dec 10, 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.

Entity platform error in 0.77.0b0

5 participants