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
Change check for existence of options flow #61147
Conversation
Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration ( |
test seems to fail on something unrelated |
@marcelveldt It's not unrelated; |
Ah thanks, the output of the tests was very confusing. I'll dig into it |
@emontnemery fixed. Turns out there was actually an error in the original test that got hidden by the previous implementation |
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. |
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. |
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. |
@MartinHjelmare @elupus |
I think it's ok, but I'd like Paulus' opinion too. |
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
There was a problem hiding this 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 馃憤
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks much better
Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
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
Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: