Skip to content

Commit

Permalink
potential solution
Browse files Browse the repository at this point in the history
  • Loading branch information
dmulcahey committed Aug 14, 2024
1 parent 81a3e4f commit dd28120
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions zigpy/quirks/v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,29 @@ class ZCLEnumMetadata(EntityMetadata):
enum: type[Enum] = attrs.field()
attribute_name: str = attrs.field()

def __hash__(self) -> int:
"""Return the hash of the metadata."""
return hash(
(
self.endpoint_id,
self.cluster_id,
self.cluster_type,
self.enum.__class__.__name__,
self.attribute_name,
self.entity_platform,
self.entity_type,
self.initially_disabled,
self.attribute_initialized_from_cache,
self.translation_key,
)
)

def __eq__(self, other: object) -> bool:
"""Return whether the metadata is equal to another."""
if not isinstance(other, ZCLEnumMetadata):
return False
return self.__hash__() == other.__hash__()


@attrs.define(frozen=True, kw_only=True, repr=True)
class ZCLSensorMetadata(EntityMetadata):
Expand Down Expand Up @@ -371,6 +394,31 @@ def create_device(self, device: Device) -> CustomDeviceV2:
)
return CustomDeviceV2(device.application, device.ieee, device.nwk, device, self)

def __hash__(self) -> int:
"""Return the hash of the metadata."""
return hash(
(
self.manufacturer_model_metadata,
self.filters,
self.custom_device_class.__class__.__name__
if self.custom_device_class
else None,
self.device_node_descriptor,
self.skip_device_configuration,
self.adds_metadata,
self.removes_metadata,
self.replaces_metadata,
self.entity_metadata,
self.device_automation_triggers_metadata,
)
)

def __eq__(self, other: object) -> bool:
"""Return whether the metadata is equal to another."""
if not isinstance(other, QuirksV2RegistryEntry):
return False
return self.__hash__() == other.__hash__()


class QuirkBuilder:
"""Quirks V2 registry entry."""
Expand Down

0 comments on commit dd28120

Please # to comment.