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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change check for existence of options flow #61147

Merged
merged 7 commits into from Dec 7, 2021

Conversation

marcelveldt
Copy link
Member

@marcelveldt marcelveldt commented Dec 7, 2021

Proposed change

The check if a config entry flow supports options was a bit strange, only checking if the method was overridden.
This doesn't catch the situation where an integration want to conditionally provide support for the Options flow, depending on the configured device, bridge, api version etc.

The check that was there only checked if the method was overridden.
I've changed it to actually looking if the method throws an UnknownHandler exception at runtime.

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

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
Copy link

Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration (config) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@project-bot project-bot bot added this to Needs review in Dev Dec 7, 2021
@marcelveldt
Copy link
Member Author

test seems to fail on something unrelated

@emontnemery
Copy link
Contributor

@marcelveldt It's not unrelated; tests/components/config/test_config_entries.py::test_get_entries fails with this PR and passes without it.

@marcelveldt
Copy link
Member Author

tests/components/config/test_config_entries.py::test_get_entries

Ah thanks, the output of the tests was very confusing. I'll dig into it

@marcelveldt
Copy link
Member Author

@emontnemery fixed. Turns out there was actually an error in the original test that got hidden by the previous implementation

@elupus
Copy link
Contributor

elupus commented Dec 7, 2021

I thought that function actually instanciate the option flow object too. That could theoretically have side effects?

@marcelveldt
Copy link
Member Author

I thought that function actually instanciate the option flow object too. That could theoretically have side effects?

Yes by calling the function it will instantiate the OptionsFlow, I did not see any side effects while testing.

It looked kind of strange to me that this was comparing the functions instead of the result but maybe there is some underlying reason I'm overlooking.

@elupus
Copy link
Contributor

elupus commented Dec 7, 2021

Any implementation of option flow can have side effects in it's init function. For example registering a WebView or what not.

I don't know if any exist, but unless overloading of init is blocked, i think this is a bad idea. I always found it a bit strange that it returns an instance. Should have returned a constructor instead.

If you need to conditionally support option flow, you can just abort your flow directly.

@marcelveldt
Copy link
Member Author

marcelveldt commented Dec 7, 2021

If you need to conditionally support option flow, you can just abort your flow directly.

It was like that but users got an empty dialog and were confused. So changed it to raising UnknownHandler but that got me into this.

I get your point about any side effects in the init of the OptionsFlow.

Another approach is to set some instance variable that the options flow is not supported and check that too.
Doesn't solve the real issue though. I agree with you that this function should return a constructor without instantiating it.

@marcelveldt
Copy link
Member Author

marcelveldt commented Dec 7, 2021

@MartinHjelmare @elupus
I've adjusted it a bit, including an example how to use it in the Hue integration.
This doesn't change the strange method comparison to determine if OptionsFlow is supported but it allows for integrations to override the async_supports_options_flow classmethod

@MartinHjelmare
Copy link
Member

MartinHjelmare commented Dec 7, 2021

I think it's ok, but I'd like Paulus' opinion too.

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Copy link
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.

Yeah this makes a lot more sense 馃憤

Dev automation moved this from Needs review to Reviewer approved Dec 7, 2021
@balloob balloob added this to the 2021.12.0 milestone Dec 7, 2021
Copy link
Contributor

@elupus elupus left a comment

Choose a reason for hiding this comment

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

Looks much better

@balloob balloob merged commit 7c7df5b into home-assistant:dev Dec 7, 2021
Dev automation moved this from Reviewer approved to Done Dec 7, 2021
balloob added a commit that referenced this pull request Dec 7, 2021
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
@github-actions github-actions bot locked and limited conversation to collaborators Dec 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Dev
  
Done
Development

Successfully merging this pull request may close these issues.

Philips Hue Integration, "configure" button fails to display dialogue
6 participants