Repository: XKNX/xknx
Pull request #1314 (2023-08-14 18:59:17)

Parse project name from keyfiles
<!--
  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 a `project_name` attribute to the `Keyring` class.

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)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Code quality improvements to existing code or addition of tests

## 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://app.codecov.io/gh/XKNX/xknx/pull/1314?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX) Report
> Merging [#1314](https://app.codecov.io/gh/XKNX/xknx/pull/1314?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX) (b15422d) into [main](https://app.codecov.io/gh/XKNX/xknx/commit/f010d6187cb7fc00895362aa1e9470be75f51812?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX) (f010d61) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.

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

```diff
@@           Coverage Diff           @@
##             main    #1314   +/-   ##
=======================================
  Coverage   96.55%   96.55%           
=======================================
  Files         150      150           
  Lines        9582     9584    +2     
=======================================
+ Hits         9252     9254    +2     
  Misses        330      330           
```


| [Files Changed](https://app.codecov.io/gh/XKNX/xknx/pull/1314?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX) | Coverage Δ | |
|---|---|---|
| [xknx/secure/keyring.py](https://app.codecov.io/gh/XKNX/xknx/pull/1314?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX#diff-eGtueC9zZWN1cmUva2V5cmluZy5weQ==) | `98.80% <100.00%> (+<0.01%)` | :arrow_up: |


Patch:
diff --git a/docs/changelog.md b/docs/changelog.md
index 263932e6..58c679ff 100644
--- a/docs/changelog.md
+++ b/docs/changelog.md
@@ -6,6 +6,12 @@ nav_order: 2
 
 # Changelog
 
+# Unreleased changes
+
+### Secure
+
+- Parse `project_name` from an ETS Keyring.
+
 # 2.11.2 DPT 9 small negative fix 2023-07-24
 
 ### Bugfixes
diff --git a/xknx/secure/keyring.py b/xknx/secure/keyring.py
index e94c1264..0f51b630 100644
--- a/xknx/secure/keyring.py
+++ b/xknx/secure/keyring.py
@@ -262,6 +262,7 @@ class Keyring(AttributeReader):
     interfaces: list[XMLInterface]
     group_addresses: list[XMLGroupAddress]
     devices: list[XMLDevice]
+    project_name: str
     created_by: str
     created: str
     signature: bytes
@@ -393,6 +394,7 @@ class Keyring(AttributeReader):
     def parse_xml(self, node: Element) -> None:
         """Parse all needed attributes from the given node map."""
         attributes = node.attributes
+        self.project_name = self.get_attribute_value(attributes.get("Project"))
         self.created_by = self.get_attribute_value(attributes.get("CreatedBy"))
         self.created = self.get_attribute_value(attributes.get("Created"))
         self.signature = base64.b64decode(


Test patch:
diff --git a/test/secure_tests/keyring_test.py b/test/secure_tests/keyring_test.py
index aaa2ade5..71ed1a1d 100644
--- a/test/secure_tests/keyring_test.py
+++ b/test/secure_tests/keyring_test.py
@@ -213,3 +213,11 @@ class TestKeyRing:
             IndividualAddress("1.0.1"): 0,
             IndividualAddress("1.0.2"): 0,
         }
+
+    def test_keyring_metadata(self):
+        """Test keyring metadata parsing."""
+        keyring = sync_load_keyring(self.data_secure_ip, "test")
+        assert keyring.project_name == "DataSecure_only"
+        assert keyring.created_by == "ETS 5.7.7 (Build 1428)"
+        assert keyring.created == "2023-02-06T21:17:09"
+        assert keyring.xmlns == "http://knx.org/xml/keyring/1"