Refactor the MQTT option and reconfigure flow (#133342)

* Move entry options to entry.options en remove broker setup from mqtt option flow

* UPdate diagnostics to export both entry data and options

* Parameterize entry options directly not depending on migration

* Update tests to use v2 entry and add separate migration test

* use start_reconfigure_flow helper

* Update quality scale comment

* Do minor entry upgrade, and do not force to upgrade entry

* Ensure options are read from older entries

* Add comment

* Follow up on code review

* Assert config entry version checking the broker connection

* Update comment
This commit is contained in:
Jan Bouwhuis
2025-01-13 19:00:18 +01:00
committed by GitHub
parent b84a4dc120
commit b93aa760c5
15 changed files with 533 additions and 371 deletions

View File

@ -695,7 +695,12 @@ async def test_reload_entry_with_restored_subscriptions(
) -> None:
"""Test reloading the config entry with with subscriptions restored."""
# Setup the MQTT entry
entry = MockConfigEntry(domain=mqtt.DOMAIN, data={mqtt.CONF_BROKER: "test-broker"})
entry = MockConfigEntry(
domain=mqtt.DOMAIN,
data={mqtt.CONF_BROKER: "test-broker"},
version=mqtt.CONFIG_ENTRY_VERSION,
minor_version=mqtt.CONFIG_ENTRY_MINOR_VERSION,
)
entry.add_to_hass(hass)
hass.config.components.add(mqtt.DOMAIN)
with patch("homeassistant.config.load_yaml_config_file", return_value={}):
@ -800,7 +805,10 @@ async def test_default_entry_setting_are_applied(
# Config entry data is incomplete but valid according the schema
entry = MockConfigEntry(
domain=mqtt.DOMAIN, data={"broker": "test-broker", "port": 1234}
domain=mqtt.DOMAIN,
data={"broker": "test-broker", "port": 1234},
version=mqtt.CONFIG_ENTRY_VERSION,
minor_version=mqtt.CONFIG_ENTRY_MINOR_VERSION,
)
entry.add_to_hass(hass)
hass.config.components.add(mqtt.DOMAIN)
@ -1614,6 +1622,8 @@ async def test_unload_config_entry(
entry = MockConfigEntry(
domain=mqtt.DOMAIN,
data={mqtt.CONF_BROKER: "test-broker"},
version=mqtt.CONFIG_ENTRY_VERSION,
minor_version=mqtt.CONFIG_ENTRY_MINOR_VERSION,
)
entry.add_to_hass(hass)