-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
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
Move more MQTT platforms to config entries #16918
Move more MQTT platforms to config entries #16918
Conversation
async_discover) | ||
|
||
|
||
async def _async_setup_platform(hass, config, async_add_entities, |
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.
It should just be called _async_setup_entity(hass, async_add_entities, config)
(in all the platforms).
Inside async_setup_platform
you know that it's always config and no longer discovery_info (as that's moved to config entries). In the setup entry discover, you know that config
is always the config.
9dbd7b9
to
e60e2b0
Compare
"""Discover and add an MQTT alarm control panel.""" | ||
config = PLATFORM_SCHEMA(discovery_payload) | ||
await _async_setup_entity(hass, config, async_add_entities, | ||
discovery_payload[ATTR_DISCOVERY_HASH]) |
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 moved the discovery_hash
attribute into this code block since it only affects components discovered through MQTT discovery. If you wish, I could also do it like this:
async def async_setup_entry(hass, config_entry, async_add_entities):
async def async_discover(discovery_payload):
config = PLATFORM_SCHEMA(discovery_payload)
await _async_setup_entity(hass, config, async_add_entities)
async def _async_setup_entity(hass, config, async_add_entities):
async_add_entities([MqttAlarm(
# ...
config.get(ATTR_DISCOVERY_HASH)
)])
|
||
async def _async_setup_entity(hass: HomeAssistantType, config: ConfigType, | ||
async_add_entities, discovery_hash=None): | ||
"""Set up MQTT sensor.""" |
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.
Also changed the method name for sensor
since it's more or less a simple rename. Let me know if I should split it off into another PR. I think I need to re-learn what is acceptable to be in one PR and what's not 😅
@OttoWinter After this is merged, MQTT discovery only accepts a single device per platform (one binary_sensor, one light, one switch, etc). Example of error of the 2nd switch (and all subsequent):
|
@emontnemery Hmm, it only happens to platforms that you also have entries in your configuration.yaml for, right? It seems like the check in |
@OttoWinter It's reproduced also with an empty configuration.yaml |
@emontnemery Yes that would be good. I can't replicate the issue here. |
@OttoWinter Perhaps it is timing related: There's no issue if I manually publish discovery topics, but I can reproduce if the discovery messages are retained when hass starts. Issue here: #16968 |
@OttoWinter Potential fix in #16987 |
Merged PRs should not be used for enhancement discussion or bug reports. If you've found a bug it's ok to make a review with inline comments and link to an issue that reports the bug. Thanks! |
Description:
#16904, but for these new platforms:
fan
andlock
need to be dealt with later because their base classes haven't been converted to config entries yet.Checklist:
tox
. Your PR cannot be merged unless tests pass