Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / app / zap-templates / templates / chip / python-CHIPClusters-py.zapt
1 '''
2 {{> header}}
3 '''
4
5 import ctypes
6 from chip.ChipStack import *
7 from chip.exceptions import *
8
9 '''
10 TODO(#4511): This file only sends cluster commands, should add more functions.
11 '''
12
13 __all__ = ["ChipClusters"]
14
15 class ChipClusters:
16     def __init__(self, chipstack):
17         self._ChipStack = chipstack
18
19     def ListClusterCommands(self):
20         return {
21 {{#chip_server_clusters}}
22             "{{asCamelCased name false}}": {
23 {{#chip_server_cluster_commands}}
24                 "{{asCamelCased name false}}": {
25 {{#chip_server_cluster_command_arguments}}
26                     "{{asCamelCased label}}": "{{asPythonType chipType}}",
27 {{/chip_server_cluster_command_arguments}}
28                 },
29 {{/chip_server_cluster_commands}}
30             },
31 {{/chip_server_clusters}}
32         }
33
34     def ListClusterAttributes(self):
35         return {
36 {{#chip_server_clusters}}
37             "{{asCamelCased name false}}": [
38 {{#chip_server_cluster_attributes}}
39                 "{{asCamelCased name false}}",
40 {{/chip_server_cluster_attributes}}
41             ],
42 {{/chip_server_clusters}}
43         }
44
45     def SendCommand(self, device: ctypes.c_void_p, cluster: str, command: str, endpoint: int, groupid: int, args):
46         func = getattr(self, "Cluster{}_Command{}".format(cluster, command), None)
47         if not func:
48             raise UnknownCommand(cluster, command)
49         func(device, endpoint, groupid, **args)
50
51     def ReadAttribute(self, device: ctypes.c_void_p, cluster: str, attribute: str, endpoint: int, groupid: int):
52         func = getattr(self, "Cluster{}_ReadAttribute{}".format(cluster, attribute), None)
53         if not func:
54             raise UnknownAttribute(cluster, attribute)
55         func(device, endpoint, groupid)
56
57     # Cluster commands
58
59 {{#chip_server_clusters}}
60 {{#chip_server_cluster_commands}}
61     def Cluster{{asCamelCased clusterName false}}_Command{{asCamelCased name false}}(self, device: ctypes.c_void_p, ZCLendpoint: int, ZCLgroupid: int{{#chip_server_cluster_command_arguments}}, {{asCamelCased label}}: {{asPythonType chipType}}{{/chip_server_cluster_command_arguments}}):
62 {{#chip_server_cluster_command_arguments}}
63 {{#if (isCharString type)}}
64         {{asCamelCased label}} = {{asCamelCased label}}.encode("utf-8") + b'\x00'
65 {{/if}}
66 {{/chip_server_cluster_command_arguments}}
67         self._ChipStack.Call(
68             lambda: self._chipLib.chip_ime_AppendCommand_{{asCamelCased clusterName false}}_{{asCamelCased name false}}(
69                 device, ZCLendpoint, ZCLgroupid{{#chip_server_cluster_command_arguments}}, {{asCamelCased label}}{{#if (isString type)}}, len({{asCamelCased label}}){{/if}}{{/chip_server_cluster_command_arguments}}
70             )
71         )
72 {{/chip_server_cluster_commands}}
73 {{/chip_server_clusters}}
74
75     # Cluster attributes
76
77 {{#chip_server_clusters}}
78 {{#chip_server_cluster_attributes}}
79     def Cluster{{asCamelCased parent.name false}}_ReadAttribute{{asCamelCased name false}}(self, device: ctypes.c_void_p, ZCLendpoint: int, ZCLgroupid: int):
80         self._ChipStack.Call(
81             lambda: self._chipLib.chip_ime_ReadAttribute_{{asCamelCased parent.name false}}_{{asCamelCased name false}}(device, ZCLendpoint, ZCLgroupid)
82         )
83 {{/chip_server_cluster_attributes}}
84 {{/chip_server_clusters}}
85
86     # Init native functions
87
88     def InitLib(self, chipLib):
89         self._chipLib = chipLib
90 {{#chip_server_clusters}}
91         # Cluster {{asCamelCased name false}}
92 {{#chip_server_cluster_commands}}
93         # Cluster {{asCamelCased clusterName false}} Command {{asCamelCased name false}}
94         self._chipLib.chip_ime_AppendCommand_{{asCamelCased clusterName false}}_{{asCamelCased name false}}.argtypes = [ctypes.c_void_p, ctypes.c_uint8, ctypes.c_uint16{{#chip_server_cluster_command_arguments}}{{#if (isString type)}}, ctypes.c_char_p, ctypes.c_uint32{{else}}, ctypes.{{asPythonCType chipType}}{{/if}}{{/chip_server_cluster_command_arguments}}]
95         self._chipLib.chip_ime_AppendCommand_{{asCamelCased clusterName false}}_{{asCamelCased name false}}.restype = ctypes.c_uint32
96 {{/chip_server_cluster_commands}}
97 {{#chip_server_cluster_attributes}}
98         # Cluster {{asCamelCased parent.name false}} ReadAttribute {{asCamelCased name false}}
99         self._chipLib.chip_ime_ReadAttribute_{{asCamelCased parent.name false}}_{{asCamelCased name false}}.argtypes = [ctypes.c_void_p, ctypes.c_uint8, ctypes.c_uint16]
100         self._chipLib.chip_ime_ReadAttribute_{{asCamelCased parent.name false}}_{{asCamelCased name false}}.restype = ctypes.c_uint32
101 {{/chip_server_cluster_attributes}}
102 {{/chip_server_clusters}}