-
-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Explicitly allow Platform enum in discovery helper #63571
Explicitly allow Platform enum in discovery helper #63571
Conversation
Hey there @jeroenterheerdt, mind taking a look at this pull request as it has been labeled with an integration ( |
Hey there @flacjacket, mind taking a look at this pull request as it has been labeled with an integration ( |
Hey there @OverloadUT, mind taking a look at this pull request as it has been labeled with an integration ( |
Hey there @michaelarnauts, mind taking a look at this pull request as it has been labeled with an integration ( |
This reverts commit bfff08f.
I have renamed the arguments. And I have kept just a single component (amcrest) to show how it would be used. |
homeassistant/helpers/discovery.py
Outdated
if component not in hass.config.components: | ||
setup_success = await setup.async_setup_component(hass, component, hass_config) | ||
# Ensure that the underlying platform domain is setup | ||
platform_domain = platform.value if isinstance(platform, Platform) else platform |
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.
We could add a frame.report
here if we want to encourage people to use the Platform enum.
For example "if platform is a string and platform could be in Platform then report the frame"
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.
but since Platform is a helper and not a definitive list maybe it is not necessary to report it
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.
I think the better long term option would be to at some point update the type again and only allow Platform
not str
anymore. For now it's perfectly fine to pass a str
. As I mentioned, they behave the same.
cc @scop as you were heavily involved in the StrEnum |
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.
Similar comments to #63581 (review)
As for requiring Platform
enum (with typing), at some point this might be an option. Don't know what others think about it though. I seem to remember that Paulus once said he is fine with passing a string. Not sure that's still current. home-assistant/architecture#663 (comment)
homeassistant/helpers/discovery.py
Outdated
if component not in hass.config.components: | ||
setup_success = await setup.async_setup_component(hass, component, hass_config) | ||
# Ensure that the underlying platform domain is setup | ||
platform_domain = platform.value if isinstance(platform, Platform) else platform |
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.
I think the better long term option would be to at some point update the type again and only allow Platform
not str
anymore. For now it's perfectly fine to pass a str
. As I mentioned, they behave the same.
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 good!
Proposed change
Add Platform to type hint in
homeassistant/helpers/discovery.py
Adjust a few components accordingly (will need a follow-up PR to adjust all components but they are here as a sample)
cc @frenck / @cdce8p / @MartinHjelmare
This is a follow-up to the discussion in #63495 (comment)
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: