Skip to content
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

Allow storing device options in DeviceEntry #59668

Closed
wants to merge 1 commit into from
Closed

Conversation

frenck
Copy link
Member

@frenck frenck commented Nov 14, 2021

Proposed change

This is a meta/suggestion PR at this point.

And is inspired by #58757 (review) and earlier discussions.

This change adds a fairly simple options dictionary to the DeviceEntry, in which we would allow integrations to store additional device options. These can be used for adjusting the behavior of a specific device, or, expose entities that control these parameters to adjust behavior.

This is very much in line with the ConfigEntry options (except for that one, we have a flow, in this case, we can leave it up to the integration).

This can be useful for things like:

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@probot-home-assistant probot-home-assistant bot added core small-pr PRs with less than 30 lines. labels Nov 14, 2021
@frenck
Copy link
Member Author

frenck commented Nov 14, 2021

As pointed out by @mib1185 on Discord, there is a problem with this approach. Devices are potentially shared across integrations, thus options can conflict. Does this need namespacing or something? This gets ugly fast probably.

Another option would be adding methods for getting/setting options, and making domain mandatory in these calls.

@marciogranzotto
Copy link
Contributor

marciogranzotto commented Nov 14, 2021

It would be great for #58921

Devices are potentially shared across integrations

I'm curious about how does this works. I thought that each device was bound to just one integration.

@mib1185
Copy link
Contributor

mib1185 commented Nov 14, 2021

I'm curious about how does this works. I thought that each device was bound to just one integration.

See the developer docs here https://developers.home-assistant.io/docs/device_registry_index especial the connections property 😉

@elupus
Copy link
Contributor

elupus commented Nov 15, 2021

I like having it inside the entry. If it's just calls on integration level, it would still need to figure out a storage location.

@frenck
Copy link
Member Author

frenck commented Nov 15, 2021

@elupus you mean config entry? If so, a config entry is not device level, as a config entry can provide multiple device.

If not, I think I don't understand your comment.

@frenck
Copy link
Member Author

frenck commented Nov 15, 2021

Please note ⚠️

I made this PR as a draft as an example. I have another option ready and I actually believe this PR is a wrong approach

@elupus
Copy link
Contributor

elupus commented Nov 15, 2021

@elupus you mean config entry? If so, a config entry is not device level, as a config entry can provide multiple device.

If not, I think I don't understand your comment.

No i meant the entry for the device in the device registry. I commented on your alternate approach of setters/getters. I think i thought about it backwards. I thought you intended for a integration level callback (like async_setup/restore state). But i realize that doesn't make much sense.

So setters getters in device registry could make sense. Mainly to avoid clobbering other domains settings by misstake. Could simplify code too, since you would not need an instance of the device to get device settings, just it's identifiers.

@frenck frenck closed this Nov 15, 2021
@frenck frenck deleted the frenck-2021-3005 branch November 15, 2021 12:21
@frenck frenck restored the frenck-2021-3005 branch November 15, 2021 13:00
@frenck frenck reopened this Nov 15, 2021
@frenck
Copy link
Member Author

frenck commented Nov 15, 2021

I think I have an idea on how to make this easier to use. will try to work an example out.

@frenck frenck closed this Nov 16, 2021
@frenck frenck deleted the frenck-2021-3005 branch November 16, 2021 09:43
@github-actions github-actions bot locked and limited conversation to collaborators Nov 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-signed core small-pr PRs with less than 30 lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants