blob: 79dabca16eca69f8566325878f608d1453a1436c [file] [log] [blame]
'''
{{> header}}
'''
import ctypes
__all__ = ["ChipClusters"]
class ChipClusters:
SUCCESS_DELEGATE = ctypes.CFUNCTYPE(None)
FAILURE_DELEGATE = ctypes.CFUNCTYPE(None, ctypes.c_uint8)
{{#chip_client_clusters}}
_{{asDelimitedMacro name}}_CLUSTER_INFO = {
"clusterName": "{{asUpperCamelCase name}}",
"clusterId": {{asHex code 8}},
"commands": {
{{#chip_cluster_commands}}
{{asHex code 8}}: {
"commandId": {{asHex code 8}},
"commandName": "{{asUpperCamelCase name}}",
"args": {
{{#chip_cluster_command_arguments_with_structs_expanded}}
"{{asLowerCamelCase label}}": "{{#if (isCharString type)}}str{{else}}{{asPythonType chipType}}{{/if}}",
{{/chip_cluster_command_arguments_with_structs_expanded}}
},
},
{{/chip_cluster_commands}}
},
"attributes": {
{{#chip_server_cluster_attributes}}
{{asHex code 8}}: {
"attributeName": "{{asUpperCamelCase name}}",
"attributeId": {{asHex code 8}},
"type": "{{#if (isCharString type)}}str{{else}}{{asPythonType chipType}}{{/if}}",
{{#if isReportableAttribute}}
"reportable": True,
{{/if}}
{{#if isWritableAttribute}}
"writable": True,
{{/if}}
},
{{/chip_server_cluster_attributes}}
},
}
{{/chip_client_clusters}}
_CLUSTER_ID_DICT = {
{{#chip_client_clusters}}
{{asHex code 8}}: _{{asDelimitedMacro name}}_CLUSTER_INFO,
{{/chip_client_clusters}}
}
_CLUSTER_NAME_DICT = {
{{#chip_client_clusters}}
"{{asUpperCamelCase name}}": _{{asDelimitedMacro name}}_CLUSTER_INFO,
{{/chip_client_clusters}}
}
def __init__(self, chipstack):
self._ChipStack = chipstack
def GetClusterInfoById(self, cluster_id: int):
data = ChipClusters._CLUSTER_ID_DICT.get(cluster_id, None)
if not data:
raise UnknownCluster(cluster_id)
return data
def ListClusterInfo(self):
return ChipClusters._CLUSTER_NAME_DICT
def ListClusterCommands(self):
return { clusterName: {
command["commandName"]: command["args"] for command in clusterInfo["commands"].values()
} for clusterName, clusterInfo in ChipClusters._CLUSTER_NAME_DICT.items() }
def ListClusterAttributes(self):
return { clusterName: {
attribute["attributeName"]: attribute for attribute in clusterInfo["attributes"].values()
} for clusterName, clusterInfo in ChipClusters._CLUSTER_NAME_DICT.items() }
# Init native functions
def InitLib(self, chipLib):
self._chipLib = chipLib