Repository: XKNX/xknx
Pull request #1088 (2022-11-24 21:39:57)

Add equality method for GatewayScanFilter
to be able to compare ConnectionConfig instances

<!--
  You are awesome! Thanks for contributing to our project!
  Please, DO NOT DELETE ANY TEXT from this template!.
-->
## Description
<!--
Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context.
List any dependencies that are required for this change.
-->


Fixes # (issue)

## Type of change
<!--
Please tick the applicable options.
NOTE: Ticking multiple options most likely indicates
that your change is to big and it is suggested to split it into several smaller PRs.
-->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update

## Checklist:

- [ ] The documentation has been adjusted accordingly
- [x] Tests have been added that prove the fix is effective or that the feature works
- [ ] The changes are documented in the changelog (docs/changelog.md)

codecov[bot]: # [Codecov](https://codecov.io/gh/XKNX/xknx/pull/1088?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX) Report
> Merging [#1088](https://codecov.io/gh/XKNX/xknx/pull/1088?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX) (aad594f) into [main](https://codecov.io/gh/XKNX/xknx/commit/74ef6ea9e1c45cd75614ab4e854f1b2e62639c75?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX) (74ef6ea) will **decrease** coverage by `0.01%`.
> The diff coverage is `50.00%`.

[![Impacted file tree graph](https://codecov.io/gh/XKNX/xknx/pull/1088/graphs/tree.svg?width=650&height=150&src=pr&token=irWbIygS84&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX)](https://codecov.io/gh/XKNX/xknx/pull/1088?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX)

```diff
@@            Coverage Diff             @@
##             main    #1088      +/-   ##
==========================================
- Coverage   96.29%   96.28%   -0.02%     
==========================================
  Files         138      138              
  Lines        8633     8635       +2     
==========================================
+ Hits         8313     8314       +1     
- Misses        320      321       +1     
```


| [Impacted Files](https://codecov.io/gh/XKNX/xknx/pull/1088?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX) | Coverage Δ | |
|---|---|---|
| [xknx/io/gateway\_scanner.py](https://codecov.io/gh/XKNX/xknx/pull/1088/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX#diff-eGtueC9pby9nYXRld2F5X3NjYW5uZXIucHk=) | `97.18% <50.00%> (-0.68%)` | :arrow_down: |


Patch:
diff --git a/xknx/io/gateway_scanner.py b/xknx/io/gateway_scanner.py
index 834585a8..78f05f10 100644
--- a/xknx/io/gateway_scanner.py
+++ b/xknx/io/gateway_scanner.py
@@ -192,6 +192,10 @@ class GatewayScanFilter:
             return True
         return False
 
+    def __eq__(self, other: object) -> bool:
+        """Equality for GatewayScanFilter class."""
+        return self.__dict__ == other.__dict__
+
 
 class GatewayScanner:
     """Class for searching KNX/IP devices."""


Test patch:
diff --git a/test/io_tests/connection_test.py b/test/io_tests/connection_test.py
new file mode 100644
index 00000000..fe29092f
--- /dev/null
+++ b/test/io_tests/connection_test.py
@@ -0,0 +1,15 @@
+"""Unit test for xknx.io.connection module."""
+
+from xknx.io.connection import ConnectionConfig, SecureConfig
+
+
+def test_connection_config_compare():
+    """Test ConnectionConfig comparison."""
+    assert ConnectionConfig() == ConnectionConfig()
+    assert ConnectionConfig() != ConnectionConfig(individual_address="1.1.1")
+
+
+def test_secure_config_compare():
+    """Test SecureConfig comparison."""
+    assert SecureConfig() == SecureConfig()
+    assert SecureConfig() != SecureConfig(user_id=5)
diff --git a/test/io_tests/gateway_scanner_test.py b/test/io_tests/gateway_scanner_test.py
index 40a939c3..27cb150d 100644
--- a/test/io_tests/gateway_scanner_test.py
+++ b/test/io_tests/gateway_scanner_test.py
@@ -466,6 +466,11 @@ class TestGatewayScanner:
         assert isinstance(frame_2.body, SearchRequest)
         assert frame_1.body.discovery_endpoint == HPAI(ip_addr="10.1.1.2", port=56789)
 
+    def test_gateway_scan_filter_compare(self):
+        """Test GatewayScanFilter comparison."""
+        assert GatewayScanFilter() == GatewayScanFilter()
+        assert GatewayScanFilter() != GatewayScanFilter(tunnelling=False)
+
 
 def fake_router_search_response() -> KNXIPFrame:
     """Return the KNXIPFrame of a KNX/IP Router with a SearchResponse body."""