Skip to content

Commit

Permalink
Added custom cluster for energy consumption data for Neo smart plug (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jf-wm committed Jun 21, 2024
1 parent 189a820 commit 422c860
Showing 1 changed file with 119 additions and 0 deletions.
119 changes: 119 additions & 0 deletions matter_server/common/custom_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,125 @@ def attribute_type(cls) -> ClusterObjectFieldDescriptor:
value: float32 = 0


@dataclass
class NeoCluster(Cluster, CustomClusterMixin):
"""Custom (vendor-specific) cluster for Neo - Vendor ID 4991 (0x137F)."""

id: ClassVar[int] = 0x00125DFC11

@ChipUtility.classproperty
def descriptor(cls) -> ClusterObjectDescriptor:
"""Return descriptor for this cluster."""
return ClusterObjectDescriptor(
Fields=[
ClusterObjectFieldDescriptor(
Label="wattAccumulated", Tag=0x00125D0021, Type=float32
),
ClusterObjectFieldDescriptor(
Label="watt", Tag=0x00125D0023, Type=float32
),
ClusterObjectFieldDescriptor(
Label="current", Tag=0x00125D0022, Type=float32
),
ClusterObjectFieldDescriptor(
Label="voltage", Tag=0x00125D0024, Type=float32
),
]
)

watt: float32 | None = None
wattAccumulated: float32 | None = None
voltage: float32 | None = None
current: float32 | None = None

class Attributes:
"""Attributes for the Neo Cluster."""

@dataclass
class Watt(ClusterAttributeDescriptor, CustomClusterAttributeMixin):
"""Watt Attribute within the Neo Cluster."""

@ChipUtility.classproperty
def cluster_id(cls) -> int:
"""Return cluster id."""
return 0x00125DFC11

@ChipUtility.classproperty
def attribute_id(cls) -> int:
"""Return attribute id."""
return 0x00125D0023

@ChipUtility.classproperty
def attribute_type(cls) -> ClusterObjectFieldDescriptor:
"""Return attribute type."""
return ClusterObjectFieldDescriptor(Type=float32)

value: float32 = 0

@dataclass
class WattAccumulated(ClusterAttributeDescriptor, CustomClusterAttributeMixin):
"""WattAccumulated Attribute within the Neo Cluster."""

@ChipUtility.classproperty
def cluster_id(cls) -> int:
"""Return cluster id."""
return 0x00125DFC11

@ChipUtility.classproperty
def attribute_id(cls) -> int:
"""Return attribute id."""
return 0x00125D0021

@ChipUtility.classproperty
def attribute_type(cls) -> ClusterObjectFieldDescriptor:
"""Return attribute type."""
return ClusterObjectFieldDescriptor(Type=float32)

value: float32 = 0

@dataclass
class Voltage(ClusterAttributeDescriptor, CustomClusterAttributeMixin):
"""Voltage Attribute within the Neo Cluster."""

@ChipUtility.classproperty
def cluster_id(cls) -> int:
"""Return cluster id."""
return 0x00125DFC11

@ChipUtility.classproperty
def attribute_id(cls) -> int:
"""Return attribute id."""
return 0x00125D0024

@ChipUtility.classproperty
def attribute_type(cls) -> ClusterObjectFieldDescriptor:
"""Return attribute type."""
return ClusterObjectFieldDescriptor(Type=float32)

value: float32 = 0

@dataclass
class Current(ClusterAttributeDescriptor, CustomClusterAttributeMixin):
"""Current Attribute within the Neo Cluster."""

@ChipUtility.classproperty
def cluster_id(cls) -> int:
"""Return cluster id."""
return 0x00125DFC11

@ChipUtility.classproperty
def attribute_id(cls) -> int:
"""Return attribute id."""
return 0x00125D0022

@ChipUtility.classproperty
def attribute_type(cls) -> ClusterObjectFieldDescriptor:
"""Return attribute type."""
return ClusterObjectFieldDescriptor(Type=float32)

value: float32 = 0


def check_polled_attributes(node_data: MatterNodeData) -> set[str]:
"""Check if custom attributes are present in the node data that need to be polled."""
attributes_to_poll: set[str] = set()
Expand Down

0 comments on commit 422c860

Please sign in to comment.