forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython-cluster-Objects-py.zapt
185 lines (154 loc) · 7.12 KB
/
python-cluster-Objects-py.zapt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
'''
{{> header}}
'''
# This file contains generated struct, enum, command definition.
# Users are not expected to import this file, instead, users can use import chip.clusters, which will import all symbols from this file and can get a readable, pretty naming like clusters.OnOff.commands.OnCommand
from dataclasses import dataclass, field
import typing
from enum import IntEnum
from chip import ChipUtility
from chip.tlv import uint, float32
from .ClusterObjects import ClusterObject, ClusterObjectDescriptor, ClusterObjectFieldDescriptor, ClusterCommand, ClusterAttributeDescriptor, Cluster, ClusterEvent
from .Types import Nullable, NullValue
{{#zcl_clusters}}
@dataclass
class {{asUpperCamelCase name}}(Cluster):
id: typing.ClassVar[int] = {{asHex code 4}}
@ChipUtility.classproperty
def descriptor(cls) -> ClusterObjectDescriptor:
return ClusterObjectDescriptor(
Fields = [
{{#zcl_attributes_server}}
{{#if entryType}}
ClusterObjectFieldDescriptor(Label="{{ asLowerCamelCase label }}", Tag={{asMEI manufacturerCode code}}, Type={{zapTypeToPythonClusterObjectType entryType ns=(asUpperCamelCase parent.name)}}),
{{else}}
ClusterObjectFieldDescriptor(Label="{{ asLowerCamelCase label }}", Tag={{asMEI manufacturerCode code}}, Type={{zapTypeToPythonClusterObjectType type ns=(asUpperCamelCase parent.name)}}),
{{/if}}
{{/zcl_attributes_server}}
])
{{#zcl_attributes_server}}
{{#if entryType}}
{{ asLowerCamelCase label }}: '{{zapTypeToPythonClusterObjectType entryType ns=(asUpperCamelCase parent.name)}}' = None
{{else}}
{{ asLowerCamelCase label }}: '{{zapTypeToPythonClusterObjectType type ns=(asUpperCamelCase parent.name)}}' = None
{{/if}}
{{/zcl_attributes_server}}
{{#zcl_enums}}
{{#first}}
class Enums:
{{/first}}
class {{asType label}}(IntEnum):
{{#zcl_enum_items}}
k{{asUpperCamelCase label}} = {{asHex value 2}}
{{/zcl_enum_items}}
{{/zcl_enums}}
{{#zcl_structs}}
{{#first}}
class Structs:
{{/first}}
@dataclass
class {{asUpperCamelCase name}}(ClusterObject):
@ChipUtility.classproperty
def descriptor(cls) -> ClusterObjectDescriptor:
return ClusterObjectDescriptor(
Fields = [
{{#zcl_struct_items}}
ClusterObjectFieldDescriptor(Label="{{ asLowerCamelCase label }}", Tag={{ fieldIdentifier }}, Type={{zapTypeToPythonClusterObjectType type ns=(asUpperCamelCase parent.parent.name)}}),
{{/zcl_struct_items}}
])
{{#zcl_struct_items}}
{{ asLowerCamelCase label }}: '{{zapTypeToPythonClusterObjectType type ns=(asUpperCamelCase parent.parent.name)}}' = {{getPythonFieldDefault type ns=(asUpperCamelCase parent.parent.name)}}
{{/zcl_struct_items}}
{{#last}}
{{/last}}
{{/zcl_structs}}
{{#zcl_commands}}
{{#first}}
class Commands:
{{/first}}
@dataclass
class {{asUpperCamelCase name}}(ClusterCommand):
cluster_id: typing.ClassVar[int] = {{ asHex parent.code 4 }}
command_id: typing.ClassVar[int] = {{ asHex code 4 }}
{{#if (isServer source)}}
is_client: typing.ClassVar[bool] = False
{{else}}
is_client: typing.ClassVar[bool] = True
{{/if}}
{{~#if responseName}}
response_type: typing.ClassVar[str] = '{{asUpperCamelCase responseName}}'
{{else}}
response_type: typing.ClassVar[str] = None
{{/if}}
@ChipUtility.classproperty
def descriptor(cls) -> ClusterObjectDescriptor:
return ClusterObjectDescriptor(
Fields = [
{{#zcl_command_arguments}}
ClusterObjectFieldDescriptor(Label="{{ asLowerCamelCase label }}", Tag={{ index }}, Type={{zapTypeToPythonClusterObjectType type ns=(asUpperCamelCase parent.parent.name)}}),
{{/zcl_command_arguments}}
])
{{#if mustUseTimedInvoke}}
@ChipUtility.classproperty
def must_use_timed_invoke(cls) -> bool:
return True
{{/if}}
{{#zcl_command_arguments}}
{{ asLowerCamelCase label }}: '{{zapTypeToPythonClusterObjectType type ns=(asUpperCamelCase parent.parent.name)}}' = {{getPythonFieldDefault type ns=(asUpperCamelCase parent.parent.name)}}
{{/zcl_command_arguments}}
{{/zcl_commands}}
{{#zcl_attributes_server}}
{{#first}}
class Attributes:
{{/first}}
@dataclass
class {{asUpperCamelCase label}}(ClusterAttributeDescriptor):
@ChipUtility.classproperty
def cluster_id(cls) -> int:
return {{ asHex parent.code 4 }}
@ChipUtility.classproperty
def attribute_id(cls) -> int:
return {{ asMEI manufacturerCode code }}
{{#if mustUseTimedWrite}}
@ChipUtility.classproperty
def must_use_timed_write(cls) -> bool:
return True
{{/if}}
@ChipUtility.classproperty
def attribute_type(cls) -> ClusterObjectFieldDescriptor:
{{#if entryType}}
return ClusterObjectFieldDescriptor(Type={{zapTypeToPythonClusterObjectType entryType ns=(asUpperCamelCase parent.name)}})
{{else}}
return ClusterObjectFieldDescriptor(Type={{zapTypeToPythonClusterObjectType type ns=(asUpperCamelCase parent.name)}})
{{/if}}
{{#if entryType}}
value: '{{zapTypeToPythonClusterObjectType entryType ns=(asUpperCamelCase parent.name)}}' = {{getPythonFieldDefault entryType ns=(asUpperCamelCase parent.name)}}
{{else}}
value: '{{zapTypeToPythonClusterObjectType type ns=(asUpperCamelCase parent.name)}}' = {{getPythonFieldDefault type ns=(asUpperCamelCase parent.name)}}
{{/if}}
{{/zcl_attributes_server}}
{{#zcl_events}}
{{#first}}
class Events:
{{/first}}
@dataclass
class {{asUpperCamelCase name}}(ClusterEvent):
@ChipUtility.classproperty
def cluster_id(cls) -> int:
return {{ asHex parent.code 4 }}
@ChipUtility.classproperty
def event_id(cls) -> int:
return {{ asMEI manufacturerCode code }}
@ChipUtility.classproperty
def descriptor(cls) -> ClusterObjectDescriptor:
return ClusterObjectDescriptor(
Fields = [
{{#zcl_event_fields}}
ClusterObjectFieldDescriptor(Label="{{ asLowerCamelCase name }}", Tag={{ fieldIdentifier }}, Type={{zapTypeToPythonClusterObjectType type ns=(asUpperCamelCase parent.parent.name)}}),
{{/zcl_event_fields}}
])
{{#zcl_event_fields}}
{{ asLowerCamelCase name }}: '{{zapTypeToPythonClusterObjectType type ns=(asUpperCamelCase parent.parent.name)}}' = {{getPythonFieldDefault type ns=(asUpperCamelCase parent.parent.name)}}
{{/zcl_event_fields}}
{{/zcl_events}}
{{/zcl_clusters}}