Repository: XKNX/xknx
Pull request #797 (2021-11-09 21:29:15)

Add CEMIMessageCode to CEMIFrame string representation
<!--
  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.
-->
Add CEMIMessageCode to CEMIFrame string representation to have it in `xknx.knx` log output.

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:

- [x] I have performed a self-review of my own code
- [ ] The documentation has been adjusted accordingly
- [x] The changes generate no new warnings
- [ ] Tests have been added that prove the fix is effective or that the feature works
- [ ] The changes are documented in the changelog
- [ ] The Homeassistant plugin has been adjusted in case of new config options


codecov[bot]: # [Codecov](https://codecov.io/gh/XKNX/xknx/pull/797?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX) Report
> Merging [#797](https://codecov.io/gh/XKNX/xknx/pull/797?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX) (9f20e27) into [main](https://codecov.io/gh/XKNX/xknx/commit/160b99f4b47eb25c7a160b0ad9452d51322a4dbf?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX) (160b99f) will **not change** coverage.
> The diff coverage is `n/a`.

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

```diff
@@           Coverage Diff           @@
##             main     #797   +/-   ##
=======================================
  Coverage   94.75%   94.75%           
=======================================
  Files         109      109           
  Lines        6808     6808           
=======================================
  Hits         6451     6451           
  Misses        357      357           
```


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


Patch:
diff --git a/xknx/knxip/cemi_frame.py b/xknx/knxip/cemi_frame.py
index 8a558a9f..82b3e877 100644
--- a/xknx/knxip/cemi_frame.py
+++ b/xknx/knxip/cemi_frame.py
@@ -206,6 +206,7 @@ class CEMIFrame:
             f'SourceAddress="{self.src_addr.__repr__()}" '
             f'DestinationAddress="{self.dst_addr.__repr__()}" '
             f'Flags="{self.flags:16b}" '
+            f'code="{self.code.name}" '
             f'payload="{self.payload}" />'
         )
 


Test patch:
diff --git a/test/str_test.py b/test/str_test.py
index 1f4dc50a..f782fd3a 100644
--- a/test/str_test.py
+++ b/test/str_test.py
@@ -515,8 +515,8 @@ class TestStringRepresentations:
         connect_request.data_endpoint = HPAI(ip_addr="192.168.42.2", port=33942)
         assert (
             str(connect_request)
-            == '<ConnectRequest control_endpoint="<HPAI 192.168.42.1:33941 />" data_endpoint="<HPAI 192.168.42.2:33942 />" request_type="ConnectRequest'
-            'Type.TUNNEL_CONNECTION" />'
+            == '<ConnectRequest control_endpoint="<HPAI 192.168.42.1:33941 />" data_endpoint="<HPAI 192.168.42.2:33942 />" '
+            'request_type="ConnectRequestType.TUNNEL_CONNECTION" />'
         )
 
     def test_connect_response(self):
@@ -529,8 +529,9 @@ class TestStringRepresentations:
         connect_response.identifier = 42
         assert (
             str(connect_response)
-            == '<ConnectResponse communication_channel="13" status_code="ErrorCode.E_NO_ERROR" control_endpoint="<HPAI 192.168.42.1:33941 />" request_t'
-            'ype="ConnectRequestType.TUNNEL_CONNECTION" identifier="42" />'
+            == '<ConnectResponse communication_channel="13" status_code="ErrorCode.E_NO_ERROR" '
+            'control_endpoint="<HPAI 192.168.42.1:33941 />" '
+            'request_type="ConnectRequestType.TUNNEL_CONNECTION" identifier="42" />'
         )
 
     def test_disconnect_request(self):
@@ -609,8 +610,9 @@ class TestStringRepresentations:
         tunnelling_request.sequence_counter = 42
         assert (
             str(tunnelling_request)
-            == '<TunnellingRequest communication_channel_id="23" sequence_counter="42" cemi="<CEMIFrame SourceAddress="IndividualAddress("0.0.0")"'
-            ' DestinationAddress="GroupAddress("0/0/0")" Flags="               0" payload="None" />" />'
+            == '<TunnellingRequest communication_channel_id="23" sequence_counter="42" '
+            'cemi="<CEMIFrame SourceAddress="IndividualAddress("0.0.0")" DestinationAddress="GroupAddress("0/0/0")" '
+            'Flags="               0" code="L_DATA_REQ" payload="None" />" />'
         )
 
     def test_tunnelling_ack(self):
@@ -635,8 +637,8 @@ class TestStringRepresentations:
         )
         assert (
             str(cemi_frame)
-            == '<CEMIFrame SourceAddress="GroupAddress("1/2/3")" DestinationAddress="GroupAddress("1/2/5")" Flags="1011110011100000" '
-            'payload="<GroupValueWrite value="<DPTBinary value="7" />" />" />'
+            == '<CEMIFrame SourceAddress="GroupAddress("1/2/3")" DestinationAddress="GroupAddress("1/2/5")" '
+            'Flags="1011110011100000" code="L_DATA_IND" payload="<GroupValueWrite value="<DPTBinary value="7" />" />" />'
         )
 
     def test_knxip_frame(self):
@@ -646,8 +648,8 @@ class TestStringRepresentations:
         knxipframe.init(KNXIPServiceType.SEARCH_REQUEST)
         assert (
             str(knxipframe)
-            == '<KNXIPFrame <KNXIPHeader HeaderLength="6" ProtocolVersion="16" KNXIPServiceType="SEARCH_REQUEST" Reserve="0" TotalLeng'
-            'th="0" />\n'
+            == '<KNXIPFrame <KNXIPHeader HeaderLength="6" ProtocolVersion="16" KNXIPServiceType="SEARCH_REQUEST" '
+            'Reserve="0" TotalLength="0" />\n'
             ' body="<SearchRequest discovery_endpoint="<HPAI 224.0.23.12:3671 />" />" />'
         )
 
@@ -677,5 +679,6 @@ class TestStringRepresentations:
         routing_indication = RoutingIndication(xknx)
         assert (
             str(routing_indication)
-            == '<RoutingIndication cemi="<CEMIFrame SourceAddress="IndividualAddress("0.0.0")" DestinationAddress="GroupAddress("0/0/0")" Flags="               0" payload="None" />" />'
+            == '<RoutingIndication cemi="<CEMIFrame SourceAddress="IndividualAddress("0.0.0")" '
+            'DestinationAddress="GroupAddress("0/0/0")" Flags="               0" code="L_DATA_IND" payload="None" />" />'
         )