blob: 9917fecb1ba5b2a1597c68da96c603e5439fc5ec [file] [log] [blame]
'''
{{> header}}
'''
import ctypes
from chip import exceptions
__all__ = ["ChipClusters"]
class ChipClusters:
SUCCESS_DELEGATE = ctypes.CFUNCTYPE(None)
FAILURE_DELEGATE = ctypes.CFUNCTYPE(None, ctypes.c_uint8)
{{#all_user_clusters side='client'}}
_{{asDelimitedMacro name}}_CLUSTER_INFO = {
"clusterName": "{{asUpperCamelCase name}}",
"clusterId": {{asHex code 8}},
"commands": {
{{#all_user_cluster_generated_commands}}
{{#if_compare clusterId ../id operator='=='}}
{{#if (is_str_equal commandSource 'client')}}
{{asHex commandCode 8}}: {
"commandId": {{asHex commandCode 8}},
"commandName": "{{asUpperCamelCase commandName}}",
"args": {
{{#zcl_command_arguments}}
{{#if_is_struct type}}
{{#zcl_struct_items_by_struct_and_cluster_name type ../../name}}
"{{asLowerCamelCase label}}": "{{#if (isCharString type)}}str{{else}}{{as_underlying_python_zcl_type type ../../../id}}{{/if}}",
{{/zcl_struct_items_by_struct_and_cluster_name}}
{{else}}
"{{asLowerCamelCase label}}": "{{#if (isCharString type)}}str{{else}}{{as_underlying_python_zcl_type type ../../id}}{{/if}}",
{{/if_is_struct}}
{{/zcl_command_arguments}}
},
},
{{/if}}
{{/if_compare}}
{{/all_user_cluster_generated_commands}}
},
"attributes": {
{{#zcl_attributes_server removeKeys='isOptional'}}
{{asHex code 8}}: {
"attributeName": "{{asUpperCamelCase name}}",
"attributeId": {{asHex code 8}},
"type": "{{as_underlying_python_zcl_type type ../id}}",
{{#if isReportableAttribute}}
"reportable": True,
{{/if}}
{{#if isWritableAttribute}}
"writable": True,
{{/if}}
},
{{/zcl_attributes_server}}
},
}
{{/all_user_clusters}}
_CLUSTER_ID_DICT = {
{{#all_user_clusters side='client'}}
{{asHex code 8}}: _{{asDelimitedMacro name}}_CLUSTER_INFO,
{{/all_user_clusters}}
}
_CLUSTER_NAME_DICT = {
{{#all_user_clusters side='client'}}
"{{asUpperCamelCase name}}": _{{asDelimitedMacro name}}_CLUSTER_INFO,
{{/all_user_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 exceptions.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