From 1d4cba0e0ae103b92926dc229fb2096e09792ccc Mon Sep 17 00:00:00 2001 From: David Mulcahey Date: Sun, 14 Jul 2024 16:53:28 -0400 Subject: [PATCH] coverage and fixes --- tests/test_quirks_v2.py | 16 +++++++++++++++- zigpy/quirks/v2/__init__.py | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/test_quirks_v2.py b/tests/test_quirks_v2.py index 1321970bc..c9311671b 100644 --- a/tests/test_quirks_v2.py +++ b/tests/test_quirks_v2.py @@ -100,7 +100,7 @@ class AttributeDefs( # pylint: disable=disallowed-name, invalid-name report: Final = ZCLAttributeDef(id=0x0000, type=t.uint8_t) - ( + entry = ( add_to_registry_v2( device_mock.manufacturer, device_mock.model, registry=registry ) @@ -118,6 +118,9 @@ class AttributeDefs( .build() ) + # coverage for overridden __eq__ method + assert entry.adds_metadata[0] != entry.adds_metadata[1] + quirked = registry.get_device(device_mock) assert isinstance(quirked, CustomDeviceV2) assert quirked in registry @@ -649,6 +652,11 @@ async def test_quirks_v2_command_button(device_mock): OnOff.cluster_id, command_kwargs={"on_off_control": OnOff.OnOffControl.Accept_Only_When_On}, ) + .command_button( + OnOff.ServerCommandDefs.on_with_timed_off.name, + OnOff.cluster_id, + command_kwargs={"on_off_control_foo": OnOff.OnOffControl.Accept_Only_When_On}, + ) .build() ) @@ -671,6 +679,12 @@ async def test_quirks_v2_command_button(device_mock): assert len(button.kwargs) == 1 assert button.kwargs["on_off_control"] == OnOff.OnOffControl.Accept_Only_When_On + # coverage for overridden eq method + assert button != quirked_device.exposes_metadata[ + (1, OnOff.cluster_id, ClusterType.Server) + ][1] + + async def test_quirks_v2_also_applies_to(device_mock): """Test adding the same quirk for multiple manufacturers and models.""" diff --git a/zigpy/quirks/v2/__init__.py b/zigpy/quirks/v2/__init__.py index a4324be97..b581ec5f7 100644 --- a/zigpy/quirks/v2/__init__.py +++ b/zigpy/quirks/v2/__init__.py @@ -202,7 +202,7 @@ def __hash__(self) -> int: def __eq__(self, other: object) -> bool: """Return whether this object is equal to another object.""" - if not isinstance(other, QuirksV2RegistryEntry): + if not isinstance(other, AddsMetadata): return False return self.__hash__() == other.__hash__() @@ -374,7 +374,7 @@ def __hash__(self) -> int: def __eq__(self, other: object) -> bool: """Return whether this object is equal to another object.""" - if not isinstance(other, QuirksV2RegistryEntry): + if not isinstance(other, ZCLCommandButtonMetadata): return False return self.__hash__() == other.__hash__()