Skip to content

Add configurable interface route metric#6447

Merged
agners merged 5 commits intohome-assistant:mainfrom
davidrapan:dev-route_metric
Jan 28, 2026
Merged

Add configurable interface route metric#6447
agners merged 5 commits intohome-assistant:mainfrom
davidrapan:dev-route_metric

Conversation

@davidrapan
Copy link
Copy Markdown
Contributor

@davidrapan davidrapan commented Dec 21, 2025

Proposed change

Add route-metric configuration option, as I recently encountered the need to fine-tune IPv4 route metric in my multi-VLAN environment (lan, iot, public), because I limit internet access in iot network, and had to resort to using nmcli again. :)

I will follow up w/ documentation and cli PRs after initial review. 😉

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (which adds functionality to the supervisor)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Ruff (ruff format supervisor tests)
  • Tests have been added to verify that the new code works.

If API endpoints or add-on configuration are added/changed:

Signed-off-by: David Rapan <david@rapan.cz>
Signed-off-by: David Rapan <david@rapan.cz>
Signed-off-by: David Rapan <david@rapan.cz>
Signed-off-by: David Rapan <david@rapan.cz>
Signed-off-by: David Rapan <david@rapan.cz>
@mdegat01 mdegat01 added the new-feature A new feature label Jan 22, 2026
Copy link
Copy Markdown
Contributor

@mdegat01 mdegat01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved although would like to know why the one test was removed before merging. Generally feature request PRs should minimize changes to existing tests so we can confirm it does not break existing functionality.

Also can you provide some more info on how you're leveraging this from HA? Does this option only make sense if you also use ha network vlan to create multiple interfaces or is there some value in setting it for someone only using the primary interface?

Comment thread tests/api/test_network.py
Comment on lines -95 to -117
async def test_api_network_interface_info_default(api_client: TestClient):
"""Test network manager default api."""
resp = await api_client.get("/network/interface/default/info")
result = await resp.json()
assert result["data"]["ipv4"]["address"][-1] == "192.168.2.148/24"
assert result["data"]["ipv4"]["gateway"] == "192.168.2.1"
assert result["data"]["ipv4"]["nameservers"] == ["192.168.2.2"]
assert result["data"]["ipv4"]["ready"] is True
assert (
result["data"]["ipv6"]["address"][0] == "2a03:169:3df5:0:6be9:2588:b26a:a679/64"
)
assert result["data"]["ipv6"]["address"][1] == "2a03:169:3df5::2f1/128"
assert result["data"]["ipv6"]["gateway"] == "fe80::da58:d7ff:fe00:9c69"
assert result["data"]["ipv6"]["nameservers"] == [
"2001:1620:2777:1::10",
"2001:1620:2777:2::20",
]
assert result["data"]["ipv6"]["ready"] is True
assert result["data"]["interface"] == TEST_INTERFACE_ETH_NAME
assert result["data"]["mdns"] == "announce"
assert result["data"]["llmnr"] == "announce"


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this test dropped?

Copy link
Copy Markdown
Contributor Author

@davidrapan davidrapan Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it's just a special case of:

async def test_api_network_interface_info(api_client: TestClient, interface_id: str):

so I though of optimizing it by dropping it and extending params to also check default interface.

The coverage remains exactly the same. It just reuses existing code.

Edit: I can do it in separate PR, but I think it should be done. :)

@davidrapan
Copy link
Copy Markdown
Contributor Author

davidrapan commented Jan 23, 2026

Also can you provide some more info on how you're leveraging this from HA? Does this option only make sense if you also use ha network vlan to create multiple interfaces or is there some value in setting it for someone only using the primary interface?

Personally, I only use it in the scope of VLANs, yes, but in general I don't see why HA shouldn't work with multiple physical interfaces, where route metrics would also have a say. I just didn't tried that one yet.

Edit (some more info about my prod env): I'm also multihoming and the HA has direct access to both ISPs (using VLANs) as one is used only for incoming connections and the other for outgoing (+ the other one also serves as the fallback and vice versa).

Edit2: "Is there some value in setting it for someone only using the primary interface?": I don't think so.

+ I'm not sure if the default value should be None (current implementation) or -1. What do you think?

@agners
Copy link
Copy Markdown
Member

agners commented Jan 26, 2026

  • I'm not sure if the default value should be None (current implementation) or -1. What do you think?

I was wondering the same in other places a couple weeks back. The optional NetworkManager settings can simply not be set. So I'd make Python None to translate to not setting the property. From what I can tell that is what your code is doing now.

Copy link
Copy Markdown
Member

@agners agners left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mdegat01 mdegat01 added the needs-client-library Pull requests needs client library changes but none is linked label Jan 27, 2026
@agners agners merged commit 641b205 into home-assistant:main Jan 28, 2026
22 of 23 checks passed
@davidrapan
Copy link
Copy Markdown
Contributor Author

davidrapan commented Jan 28, 2026

PR has needs-client-library, but just like w/ ipv6-addr-gen-mode, I don't think it needs to be exposed through the frontend. Or is it?

@github-actions github-actions Bot locked and limited conversation to collaborators Jan 30, 2026
@mdegat01 mdegat01 removed the needs-client-library Pull requests needs client library changes but none is linked label Mar 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants