nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: XKNX/xknx
Pull request #1230 (2023-03-24 22:16:39)

Handle empty list for group address
<!--
  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.
-->
Handle empty list for group address. This would previously raise `ValueError: not enough values to unpack` and leave a devices unusable (`_iter_remote_values` would then raise).
Now this is treated like `None`.

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.
-->

- [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)
- [ ] 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)


Patch:
diff --git a/docs/changelog.md b/docs/changelog.md
index a086276c..1fbf6fb7 100644
--- a/docs/changelog.md
+++ b/docs/changelog.md
@@ -6,6 +6,12 @@ nav_order: 2
 
 # Changelog
 
+# Unreleased changes
+
+### Bugfixes
+
+- Handle empty list for group addresses in RemoteValue.
+
 # 2.7.0 IP Device Management 2023-03-15
 
 ### Protocol
diff --git a/xknx/remote_value/remote_value.py b/xknx/remote_value/remote_value.py
index e8c1a5c0..681f5d8f 100644
--- a/xknx/remote_value/remote_value.py
+++ b/xknx/remote_value/remote_value.py
@@ -56,7 +56,7 @@ class RemoteValue(ABC, Generic[DPTPayloadT, ValueT]):
             addresses: GroupAddressesType | None,
         ) -> DeviceGroupAddress | None:
             """Parse group addresses and assign passive addresses when given."""
-            if addresses is None:
+            if not addresses:  # None or empty list
                 return None
             if not isinstance(addresses, list):
                 return parse_device_group_address(addresses)


Test patch:
diff --git a/test/remote_value_tests/remote_value_test.py b/test/remote_value_tests/remote_value_test.py
index 59ffe2d0..3e9fe922 100644
--- a/test/remote_value_tests/remote_value_test.py
+++ b/test/remote_value_tests/remote_value_test.py
@@ -223,6 +223,9 @@ class TestRemoteValue:
         assert remote_value_3.has_group_address(GroupAddress("2/2/2"))
         assert remote_value_3.has_group_address(GroupAddress("2/2/20"))
         assert not remote_value_3.has_group_address(GroupAddress("0/0/0"))
+        # test empty list
+        remote_value_4 = RemoteValue(xknx, group_address=[])
+        assert remote_value_4.group_address is None
 
     async def test_process_passive_address(self):
         """Test if passive group addresses are processed."""