diff --git a/homeassistant/components/mqtt/config_flow.py b/homeassistant/components/mqtt/config_flow.py index b022a46cbe7..ee451b5f81d 100644 --- a/homeassistant/components/mqtt/config_flow.py +++ b/homeassistant/components/mqtt/config_flow.py @@ -2771,11 +2771,10 @@ class MQTTSubentryFlowHandler(ConfigSubentryFlow): reconfig=True, ) if user_input is not None: - new_device_data, errors = validate_user_input( - user_input, MQTT_DEVICE_PLATFORM_FIELDS - ) - if "mqtt_settings" in user_input: - new_device_data["mqtt_settings"] = user_input["mqtt_settings"] + new_device_data: dict[str, Any] = user_input.copy() + _, errors = validate_user_input(user_input, MQTT_DEVICE_PLATFORM_FIELDS) + if "advanced_settings" in new_device_data: + new_device_data |= new_device_data.pop("advanced_settings") if not errors: self._subentry_data[CONF_DEVICE] = cast(MqttDeviceData, new_device_data) if self.source == SOURCE_RECONFIGURE: diff --git a/tests/components/mqtt/test_config_flow.py b/tests/components/mqtt/test_config_flow.py index 12f77a95c48..9386f1da32c 100644 --- a/tests/components/mqtt/test_config_flow.py +++ b/tests/components/mqtt/test_config_flow.py @@ -4077,6 +4077,7 @@ async def test_subentry_reconfigure_update_device_properties( "model": "Beer bottle XL", "model_id": "bn003", "configuration_url": "https://example.com", + "mqtt_settings": {"qos": 1}, }, ) assert result["type"] is FlowResultType.MENU @@ -4090,12 +4091,15 @@ async def test_subentry_reconfigure_update_device_properties( assert result["type"] is FlowResultType.ABORT assert result["reason"] == "reconfigure_successful" - # Check our device was updated + # Check our device and mqtt data was updated correctly device = deepcopy(dict(subentry.data))["device"] assert device["name"] == "Beer notifier" assert "hw_version" not in device assert device["model"] == "Beer bottle XL" assert device["model_id"] == "bn003" + assert device["sw_version"] == "1.1" + assert device["mqtt_settings"]["qos"] == 1 + assert "qos" not in device @pytest.mark.parametrize(