Skip to content

Commit

Permalink
specify attribute paths using cluster lib
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Sep 20, 2024
1 parent 87ceab4 commit d28e130
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions matter_server/common/custom_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
ClusterObjectDescriptor,
ClusterObjectFieldDescriptor,
)
from chip.clusters.Objects import BasicInformation, ElectricalPowerMeasurement
from chip.tlv import float32, uint

from matter_server.common.helpers.util import parse_attribute_path
from matter_server.common.helpers.util import (
create_attribute_path_from_attribute,
parse_attribute_path,
)

if TYPE_CHECKING:
from matter_server.common.models import MatterNodeData
Expand All @@ -27,6 +31,8 @@
ALL_CUSTOM_CLUSTERS: dict[int, Cluster] = {}
ALL_CUSTOM_ATTRIBUTES: dict[int, dict[int, ClusterAttributeDescriptor]] = {}

VENDOR_ID_EVE = 4874


@dataclass
class CustomClusterMixin:
Expand Down Expand Up @@ -64,13 +70,19 @@ def __init_subclass__(cls: ClusterAttributeDescriptor, *args, **kwargs) -> None:

def should_poll_eve_energy(node_data: MatterNodeData) -> bool:
"""Check if the (Eve Energy) custom attribute should be polled for state changes."""
if node_data.attributes.get("0/40/2") != 4874:
attr_path = create_attribute_path_from_attribute(
0, BasicInformation.Attributes.VendorID
)
if node_data.attributes.get(attr_path) != VENDOR_ID_EVE:
# Some implementation (such as MatterBridge) use the
# Eve cluster to send the power measurements. Filter that out.
return False
# if the ElectricalPowerMeasurement cluster is NOT present,
# we should poll the custom Eve cluster attribute(s).
return node_data.attributes.get("2/144/65531") is None
attr_path = create_attribute_path_from_attribute(
2, ElectricalPowerMeasurement.Attributes.AttributeList
)
return node_data.attributes.get(attr_path) is None


@dataclass
Expand Down

0 comments on commit d28e130

Please sign in to comment.