Skip to content

Commit 8d404ab

Browse files
marcelveldtagners
andauthored
Add custom cluster definition for ThirdReality Energy reporting (#789)
Co-authored-by: Stefan Agner <stefan@agner.ch>
1 parent 750d98b commit 8d404ab

File tree

1 file changed

+89
-1
lines changed

1 file changed

+89
-1
lines changed

matter_server/common/custom_clusters.py

+89-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
ClusterObjectDescriptor,
1313
ClusterObjectFieldDescriptor,
1414
)
15-
from chip.tlv import float32
15+
from chip.tlv import float32, uint
1616

1717
from matter_server.common.helpers.util import parse_attribute_path
1818

@@ -357,6 +357,94 @@ def attribute_type(cls) -> ClusterObjectFieldDescriptor:
357357
value: float32 = 0
358358

359359

360+
@dataclass
361+
class ThirdRealityMeteringCluster(Cluster, CustomClusterMixin):
362+
"""Custom (vendor-specific) PowerMetering cluster for ThirdReality."""
363+
364+
id: ClassVar[int] = 0x130DFC02
365+
366+
@ChipUtility.classproperty
367+
def descriptor(cls) -> ClusterObjectDescriptor:
368+
"""Return descriptor for this cluster."""
369+
return ClusterObjectDescriptor(
370+
Fields=[
371+
ClusterObjectFieldDescriptor(
372+
Label="currentSummationDelivered", Tag=0x0000, Type=uint
373+
),
374+
ClusterObjectFieldDescriptor(
375+
Label="instantaneousDemand", Tag=0x0400, Type=uint
376+
),
377+
]
378+
)
379+
380+
currentSummationDelivered: uint | None = None
381+
instantaneousDemand: uint | None = None
382+
383+
class Attributes:
384+
"""Attributes for the custom Cluster."""
385+
386+
@dataclass
387+
class CurrentSummationDelivered(
388+
ClusterAttributeDescriptor, CustomClusterAttributeMixin
389+
):
390+
"""CurrentSummationDelivered represents the most recent summed value of Energy consumed in the premise.
391+
392+
CurrentSummationDelivered is updated continuously as new measurements are made.
393+
This attribute is Read only.
394+
Value is set to zero when leave command is received (beginning version 2.6.15),
395+
or local factory reset(10s) is performed on the device..
396+
"""
397+
398+
@ChipUtility.classproperty
399+
def cluster_id(cls) -> int:
400+
"""Return cluster id."""
401+
return 0x130DFC02
402+
403+
@ChipUtility.classproperty
404+
def attribute_id(cls) -> int:
405+
"""Return attribute id."""
406+
return 0x0000
407+
408+
@ChipUtility.classproperty
409+
def attribute_type(cls) -> ClusterObjectFieldDescriptor:
410+
"""Return attribute type."""
411+
return ClusterObjectFieldDescriptor(Type=uint)
412+
413+
value: uint = 0
414+
415+
@dataclass
416+
class InstantaneousDemand(
417+
ClusterAttributeDescriptor, CustomClusterAttributeMixin
418+
):
419+
"""
420+
InstantaneousDemand represents the current Demand of Energy delivered at the premise.
421+
422+
Device is able measure only positive values indicate Demand delivered to the premise.
423+
InstantaneousDemand is updated continuously as new measurements are made.
424+
The frequency of updates to this field is specific to the metering device,
425+
but should be within the range of once every second to once every 5 seconds.
426+
The same multiplier and divisor values used for Current Summation Delivered (Energy) will be used.
427+
If connected load is below 1W, this attribute is set to 0 and no accumulation of energy is done.
428+
"""
429+
430+
@ChipUtility.classproperty
431+
def cluster_id(cls) -> int:
432+
"""Return cluster id."""
433+
return 0x130DFC02
434+
435+
@ChipUtility.classproperty
436+
def attribute_id(cls) -> int:
437+
"""Return attribute id."""
438+
return 0x0400
439+
440+
@ChipUtility.classproperty
441+
def attribute_type(cls) -> ClusterObjectFieldDescriptor:
442+
"""Return attribute type."""
443+
return ClusterObjectFieldDescriptor(Type=uint)
444+
445+
value: uint = 0
446+
447+
360448
def check_polled_attributes(node_data: MatterNodeData) -> set[str]:
361449
"""Check if custom attributes are present in the node data that need to be polled."""
362450
attributes_to_poll: set[str] = set()

0 commit comments

Comments
 (0)