Repository: XKNX/xknx
Pull request #995 (2022-07-29 05:37:19)

Ignore telegrams for other devices
<!--
  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.
-->
Ignore telegrams for addressed at other devices (individual).

Fixes # (issue)
<!--
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.
-->

- [x] 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
- [x] The changes are documented in the changelog (docs/changelog.md)

codecov[bot]: # [Codecov](https://codecov.io/gh/XKNX/xknx/pull/995?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX) Report
> Merging [#995](https://codecov.io/gh/XKNX/xknx/pull/995?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX) (f8ad12f) into [main](https://codecov.io/gh/XKNX/xknx/commit/dce7ad5bd88d10ced99f683d8c7095cf92663f68?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX) (dce7ad5) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/XKNX/xknx/pull/995/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/995?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX)

```diff
@@           Coverage Diff           @@
##             main     #995   +/-   ##
=======================================
  Coverage   96.07%   96.07%           
=======================================
  Files         133      133           
  Lines        8110     8112    +2     
=======================================
+ Hits         7792     7794    +2     
  Misses        318      318           
```


| [Impacted Files](https://codecov.io/gh/XKNX/xknx/pull/995?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX) | Coverage Δ | |
|---|---|---|
| [xknx/io/knxip\_interface.py](https://codecov.io/gh/XKNX/xknx/pull/995/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX#diff-eGtueC9pby9rbnhpcF9pbnRlcmZhY2UucHk=) | `85.09% <100.00%> (+0.18%)` | :arrow_up: |


Patch:
diff --git a/docs/changelog.md b/docs/changelog.md
index 49b61511..7f74631a 100644
--- a/docs/changelog.md
+++ b/docs/changelog.md
@@ -6,6 +6,10 @@ nav_order: 2
 
 # Changelog
 
+### Management
+
+- Ignore received telegrams addressed to individual addresses other than XKNXs current address
+
 ## 0.22.0 Management 2022-07-26
 
 ### Management
diff --git a/xknx/io/knxip_interface.py b/xknx/io/knxip_interface.py
index b89a6a28..75dad02e 100644
--- a/xknx/io/knxip_interface.py
+++ b/xknx/io/knxip_interface.py
@@ -278,6 +278,8 @@ class KNXIPInterface:
     async def telegram_received(self, telegram: Telegram) -> list[Telegram] | None:
         """Put received telegram into queue. Callback for having received telegram."""
         if isinstance(telegram.destination_address, IndividualAddress):
+            if telegram.destination_address != self.xknx.current_address:
+                return None
             return self.xknx.management.process(telegram)
 
         self.xknx.telegrams.put_nowait(telegram)


Test patch:
diff --git a/test/management_tests/management_test.py b/test/management_tests/management_test.py
index 0884b2f5..9a5457ce 100644
--- a/test/management_tests/management_test.py
+++ b/test/management_tests/management_test.py
@@ -168,3 +168,33 @@ async def test_incoming_unexpected_numbered_telegram():
         tpci=tpci.TAck(0),
     )
     assert await xknx.knxip_interface.telegram_received(device_desc_read) == [ack]
+
+
+async def test_incoming_wrong_address():
+    """Test incoming telegrams addressed to different devices."""
+    xknx = XKNX()
+    individual_address = IndividualAddress("4.0.10")
+    other_address = IndividualAddress("4.0.11")
+    assert xknx.current_address != other_address
+
+    connect = Telegram(
+        source_address=individual_address,
+        destination_address=other_address,
+        direction=TelegramDirection.INCOMING,
+        tpci=tpci.TConnect(),
+    )
+    ack = Telegram(
+        source_address=individual_address,
+        destination_address=other_address,
+        direction=TelegramDirection.INCOMING,
+        tpci=tpci.TAck(0),
+    )
+    disconnect = Telegram(
+        source_address=individual_address,
+        destination_address=other_address,
+        direction=TelegramDirection.INCOMING,
+        tpci=tpci.TDisconnect(),
+    )
+    assert await xknx.knxip_interface.telegram_received(connect) is None
+    assert await xknx.knxip_interface.telegram_received(ack) is None
+    assert await xknx.knxip_interface.telegram_received(disconnect) is None