Skip to content

Conversation

@davidrapan
Copy link
Contributor

@davidrapan davidrapan commented Jan 24, 2026

Proposed change

Add options to modify route metric for ha network update & vlan

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

Summary by CodeRabbit

  • New Features
    • Added IPv4 and IPv6 route metric configuration options for network interfaces.
    • Extended VLAN interface configuration with IPv4 and IPv6 route metric settings.
    • Command-line accepts integer route-metric values and provides flag completion for these options.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 24, 2026

Warning

Rate limit exceeded

@davidrapan has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 3 minutes and 50 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

Two CLI commands (network update and network vlan) gain new IPv4/IPv6 route metric flags (defaults -1). Flag completion callbacks were added. Argument parsing was extended to accept integer flags and map the route-metric values to the API key. A new exported IsInt field was added to NetworkArg.

Changes

Cohort / File(s) Summary
Network CLI flags
cmd/network_update.go, cmd/network_vlan.go
Added ipv4-route-metric and ipv6-route-metric integer flags (default -1) and registered completion callbacks.
Argument parsing / IP config assembly
cmd/network_update.go
Extended parsing to handle integer (IsInt) flags, included IPv4/IPv6 route-metric in assembled IP config, and mapped CLI flag values to the API key route_metric.
Public API struct change
cmd/network_update.go
Added exported field IsInt bool to the NetworkArg struct to indicate integer-valued CLI arguments.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change - adding ipv4/ipv6 route metric options for network commands. It is concise, specific, and clearly relates to the primary purpose of the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cmd/network_update.go (1)

159-168: Fix int flag parsing for route metric (currently dropped).
helperIpConfig adds *-route-metric, but parseNetworkArgs only calls GetString for non-array flags. For int flags this returns an error, so route_metric never reaches the API. This effectively breaks the new feature.

✅ Suggested fix (add int support)
 type NetworkArg struct {
 	Arg     string
 	ApiKey  string
 	IsArray bool
+	IsInt   bool
 }
 
 func parseNetworkArgs(cmd *cobra.Command, args []NetworkArg) map[string]any {
 	networkConfig := make(map[string]any)
 	for _, arg := range args {
 		var val any
 		var err error
 		var changed bool
 
 		if arg.IsArray {
 			val, err = cmd.Flags().GetStringArray(arg.Arg)
 			changed = len(val.([]string)) > 0
+		} else if arg.IsInt {
+			val, err = cmd.Flags().GetInt(arg.Arg)
+			changed = true
 		} else {
 			val, err = cmd.Flags().GetString(arg.Arg)
 			changed = val.(string) != ""
 		}
 
 		if err == nil && changed && cmd.Flags().Changed(arg.Arg) {
 			networkConfig[arg.ApiKey] = val
 		}
 	}
 	return networkConfig
 }
 
 func helperIpConfig(version string, cmd *cobra.Command, options map[string]any) {
 	args := []NetworkArg{
 		{Arg: version + "-gateway", ApiKey: "gateway"},
 		{Arg: version + "-method", ApiKey: "method"},
 		{Arg: version + "-addr-gen-mode", ApiKey: "addr_gen_mode"},
 		{Arg: version + "-privacy", ApiKey: "ip6_privacy"},
 		{Arg: version + "-address", ApiKey: "address", IsArray: true},
 		{Arg: version + "-nameserver", ApiKey: "nameservers", IsArray: true},
-		{Arg: version + "-route-metric", ApiKey: "route_metric"},
+		{Arg: version + "-route-metric", ApiKey: "route_metric", IsInt: true},
 	}

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cmd/network_update.go (1)

145-154: Refactor if-else chain to switch statement per linter.

The pipeline failure indicates this if-else chain should be a switch statement. Additionally, setting changed = true unconditionally for IsInt is semantically odd (though functionally correct due to the Changed() gate at line 156).

♻️ Proposed fix
-		if arg.IsInt {
-			val, err = cmd.Flags().GetInt(arg.Arg)
-			changed = true
-		} else if arg.IsArray {
-			val, err = cmd.Flags().GetStringArray(arg.Arg)
-			changed = len(val.([]string)) > 0
-		} else {
-			val, err = cmd.Flags().GetString(arg.Arg)
-			changed = val.(string) != ""
+		switch {
+		case arg.IsInt:
+			val, err = cmd.Flags().GetInt(arg.Arg)
+			changed = true
+		case arg.IsArray:
+			val, err = cmd.Flags().GetStringArray(arg.Arg)
+			changed = len(val.([]string)) > 0
+		default:
+			val, err = cmd.Flags().GetString(arg.Arg)
+			changed = val.(string) != ""
 		}

Copy link
Member

@sairon sairon left a comment

Choose a reason for hiding this comment

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

LGTM!

@sairon sairon merged commit eb88a6a into home-assistant:master Feb 2, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants