-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support custom Clusters and Attributes (#430)
Co-authored-by: Ludovic BOUÉ <[email protected]>
- Loading branch information
1 parent
fd69a5c
commit 01c6b2f
Showing
9 changed files
with
323 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
"""Various models and helpers for (custom) Matter clusters.""" | ||
|
||
from dataclasses import dataclass | ||
from typing import ClassVar | ||
|
||
from chip import ChipUtility | ||
from chip.clusters.ClusterObjects import ( | ||
Cluster, | ||
ClusterAttributeDescriptor, | ||
ClusterObjectDescriptor, | ||
ClusterObjectFieldDescriptor, | ||
) | ||
from chip.tlv import float32 | ||
|
||
# pylint: disable=invalid-name,arguments-renamed,no-self-argument | ||
|
||
|
||
@dataclass | ||
class EveEnergyCluster(Cluster): | ||
"""Custom (vendor-specific) cluster for Eve Energy plug.""" | ||
|
||
id: ClassVar[int] = 0x130AFC01 | ||
|
||
@ChipUtility.classproperty | ||
def descriptor(cls) -> ClusterObjectDescriptor: | ||
"""Return descriptor for this cluster.""" | ||
return ClusterObjectDescriptor( | ||
Fields=[ | ||
ClusterObjectFieldDescriptor( | ||
Label="watt", Tag=0x130A000A, Type=float32 | ||
), | ||
ClusterObjectFieldDescriptor( | ||
Label="wattAccumulated", Tag=0x130A000B, Type=float32 | ||
), | ||
ClusterObjectFieldDescriptor( | ||
Label="wattAccumulatedControlPoint", Tag=0x130A000E, Type=float32 | ||
), | ||
ClusterObjectFieldDescriptor( | ||
Label="voltage", Tag=0x130A0008, Type=float32 | ||
), | ||
ClusterObjectFieldDescriptor( | ||
Label="current", Tag=0x130A0009, Type=float32 | ||
), | ||
] | ||
) | ||
|
||
watt: float32 | None = None | ||
wattAccumulated: float32 | None = None | ||
wattAccumulatedControlPoint: float32 | None = None | ||
voltage: float32 | None = None | ||
current: float32 | None = None | ||
|
||
class Attributes: | ||
"""Attributes for the EveEnergy Cluster.""" | ||
|
||
@dataclass | ||
class Watt(ClusterAttributeDescriptor): | ||
"""Watt Attribute within the EveEnergy Cluster.""" | ||
|
||
@ChipUtility.classproperty | ||
def cluster_id(cls) -> int: | ||
"""Return cluster id.""" | ||
return 0x130AFC01 | ||
|
||
@ChipUtility.classproperty | ||
def attribute_id(cls) -> int: | ||
"""Return attribute id.""" | ||
return 0x130A000A | ||
|
||
@ChipUtility.classproperty | ||
def attribute_type(cls) -> ClusterObjectFieldDescriptor: | ||
"""Return attribute type.""" | ||
return ClusterObjectFieldDescriptor(Type=float32) | ||
|
||
value: float32 = 0 | ||
|
||
@dataclass | ||
class WattAccumulated(ClusterAttributeDescriptor): | ||
"""WattAccumulated Attribute within the EveEnergy Cluster.""" | ||
|
||
@ChipUtility.classproperty | ||
def cluster_id(cls) -> int: | ||
"""Return cluster id.""" | ||
return 0x130AFC01 | ||
|
||
@ChipUtility.classproperty | ||
def attribute_id(cls) -> int: | ||
"""Return attribute id.""" | ||
return 0x130A000B | ||
|
||
@ChipUtility.classproperty | ||
def attribute_type(cls) -> ClusterObjectFieldDescriptor: | ||
"""Return attribute type.""" | ||
return ClusterObjectFieldDescriptor(Type=float32) | ||
|
||
value: float32 = 0 | ||
|
||
@dataclass | ||
class wattAccumulatedControlPoint(ClusterAttributeDescriptor): | ||
"""wattAccumulatedControlPoint Attribute within the EveEnergy Cluster.""" | ||
|
||
@ChipUtility.classproperty | ||
def cluster_id(cls) -> int: | ||
"""Return cluster id.""" | ||
return 0x130AFC01 | ||
|
||
@ChipUtility.classproperty | ||
def attribute_id(cls) -> int: | ||
"""Return attribute id.""" | ||
return 0x130A000E | ||
|
||
@ChipUtility.classproperty | ||
def attribute_type(cls) -> ClusterObjectFieldDescriptor: | ||
"""Return attribute type.""" | ||
return ClusterObjectFieldDescriptor(Type=float32) | ||
|
||
value: float32 = 0 | ||
|
||
@dataclass | ||
class Voltage(ClusterAttributeDescriptor): | ||
"""Voltage Attribute within the EveEnergy Cluster.""" | ||
|
||
@ChipUtility.classproperty | ||
def cluster_id(cls) -> int: | ||
"""Return cluster id.""" | ||
return 0x130AFC01 | ||
|
||
@ChipUtility.classproperty | ||
def attribute_id(cls) -> int: | ||
"""Return attribute id.""" | ||
return 0x130A0008 | ||
|
||
@ChipUtility.classproperty | ||
def attribute_type(cls) -> ClusterObjectFieldDescriptor: | ||
"""Return attribute type.""" | ||
return ClusterObjectFieldDescriptor(Type=float32) | ||
|
||
value: float32 = 0 | ||
|
||
@dataclass | ||
class Current(ClusterAttributeDescriptor): | ||
"""Current Attribute within the EveEnergy Cluster.""" | ||
|
||
@ChipUtility.classproperty | ||
def cluster_id(cls) -> int: | ||
"""Return cluster id.""" | ||
return 0x130AFC01 | ||
|
||
@ChipUtility.classproperty | ||
def attribute_id(cls) -> int: | ||
"""Return attribute id.""" | ||
return 0x130A0009 | ||
|
||
@ChipUtility.classproperty | ||
def attribute_type(cls) -> ClusterObjectFieldDescriptor: | ||
"""Return attribute type.""" | ||
return ClusterObjectFieldDescriptor(Type=float32) | ||
|
||
value: float32 = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.