Skip to content

Commit

Permalink
coverage and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dmulcahey committed Jul 14, 2024
1 parent 7c82543 commit 1d4cba0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 15 additions & 1 deletion tests/test_quirks_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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
Expand Down Expand Up @@ -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()
)

Expand All @@ -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."""
Expand Down
4 changes: 2 additions & 2 deletions zigpy/quirks/v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()

Expand Down Expand Up @@ -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__()

Expand Down

0 comments on commit 1d4cba0

Please # to comment.