Skip to content

Handle when legacy firewall and nat rules are empty#494

Merged
Snuffy2 merged 2 commits intotravisghansen:mainfrom
Snuffy2:Handle-when-legacy-firewall-and-nat-rules-are-empty
Feb 7, 2026
Merged

Handle when legacy firewall and nat rules are empty#494
Snuffy2 merged 2 commits intotravisghansen:mainfrom
Snuffy2:Handle-when-legacy-firewall-and-nat-rules-are-empty

Conversation

@Snuffy2
Copy link
Collaborator

@Snuffy2 Snuffy2 commented Feb 7, 2026

This pull request refactors how rules are extracted from the state object in the OPNsense integration, replacing deeply nested dictionary access with the dict_get helper for improved readability and maintainability. It also fixes a bug in the outbound NAT rule filter by using the correct key for rule descriptions and updates the related test accordingly.

Refactoring for improved maintainability and readability:

  • Replaced multiple instances of deeply nested dictionary access with the dict_get helper in all switch compilation functions in switch.py, simplifying type checks and rule extraction. [1] [2] [3] [4] [5] [6] [7] [8]

Bug fix:

  • Corrected the key used to filter out "Auto created rule" entries in outbound NAT rules from description to descr, ensuring proper rule filtering.

Testing:

  • Updated the outbound NAT rule test data to use the descr key instead of description, matching the code change.

Minor cleanup:

  • Commented out unnecessary debug logging in the firewall and NAT rule retrieval functions for cleaner logs. [1] [2]

Partially addresses #488

@Snuffy2 Snuffy2 added the bugfix Fix something that isn't working label Feb 7, 2026
@Snuffy2 Snuffy2 merged commit 80e2e9e into travisghansen:main Feb 7, 2026
5 checks passed
@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2026

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  custom_components/opnsense
  switch.py 127, 175, 180, 414, 462, 502, 507, 547, 552, 592, 597
  custom_components/opnsense/pyopnsense
  __init__.py
Project Total  

This report was generated by python-coverage-comment-action

@Snuffy2 Snuffy2 deleted the Handle-when-legacy-firewall-and-nat-rules-are-empty branch February 7, 2026 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fix something that isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant