-
Notifications
You must be signed in to change notification settings - Fork 531
Expand file tree
/
Copy pathinit.lua
More file actions
281 lines (261 loc) · 9.38 KB
/
init.lua
File metadata and controls
281 lines (261 loc) · 9.38 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
-- Copyright 2026 SmartThings, Inc.
-- Licensed under the Apache License, Version 2.0
local cluster_base = require "st.matter.cluster_base"
local DoorLockServerAttributes = require "DoorLock.server.attributes"
local DoorLockServerCommands = require "DoorLock.server.commands"
local DoorLockClientCommands = require "DoorLock.client.commands"
local DoorLockEvents = require "DoorLock.server.events"
local DoorLockTypes = require "DoorLock.types"
local DoorLock = {}
DoorLock.ID = 0x0101
DoorLock.NAME = "DoorLock"
DoorLock.server = {}
DoorLock.client = {}
DoorLock.server.attributes = DoorLockServerAttributes:set_parent_cluster(DoorLock)
DoorLock.server.commands = DoorLockServerCommands:set_parent_cluster(DoorLock)
DoorLock.client.commands = DoorLockClientCommands:set_parent_cluster(DoorLock)
DoorLock.server.events = DoorLockEvents:set_parent_cluster(DoorLock)
DoorLock.types = DoorLockTypes
function DoorLock:get_attribute_by_id(attr_id)
local attr_id_map = {
[0x0000] = "LockState",
[0x0001] = "LockType",
[0x0002] = "ActuatorEnabled",
[0x0003] = "DoorState",
[0x0004] = "DoorOpenEvents",
[0x0005] = "DoorClosedEvents",
[0x0006] = "OpenPeriod",
[0x0011] = "NumberOfTotalUsersSupported",
[0x0012] = "NumberOfPINUsersSupported",
[0x0013] = "NumberOfRFIDUsersSupported",
[0x0014] = "NumberOfWeekDaySchedulesSupportedPerUser",
[0x0015] = "NumberOfYearDaySchedulesSupportedPerUser",
[0x0016] = "NumberOfHolidaySchedulesSupported",
[0x0017] = "MaxPINCodeLength",
[0x0018] = "MinPINCodeLength",
[0x0019] = "MaxRFIDCodeLength",
[0x001A] = "MinRFIDCodeLength",
[0x001B] = "CredentialRulesSupport",
[0x001C] = "NumberOfCredentialsSupportedPerUser",
[0x0021] = "Language",
[0x0022] = "LEDSettings",
[0x0023] = "AutoRelockTime",
[0x0024] = "SoundVolume",
[0x0025] = "OperatingMode",
[0x0026] = "SupportedOperatingModes",
[0x0027] = "DefaultConfigurationRegister",
[0x0028] = "EnableLocalProgramming",
[0x0029] = "EnableOneTouchLocking",
[0x002A] = "EnableInsideStatusLED",
[0x002B] = "EnablePrivacyModeButton",
[0x002C] = "LocalProgrammingFeatures",
[0x0030] = "WrongCodeEntryLimit",
[0x0031] = "UserCodeTemporaryDisableTime",
[0x0032] = "SendPINOverTheAir",
[0x0033] = "RequirePINforRemoteOperation",
[0x0035] = "ExpiringUserTimeout",
[0x0080] = "AliroReaderVerificationKey",
[0x0081] = "AliroReaderGroupIdentifier",
[0x0082] = "AliroReaderGroupSubIdentifier",
[0x0083] = "AliroExpeditedTransactionSupportedProtocolVersions",
[0x0084] = "AliroGroupResolvingKey",
[0x0085] = "AliroSupportedBLEUWBProtocolVersions",
[0x0086] = "AliroBLEAdvertisingVersion",
[0x0087] = "NumberOfAliroCredentialIssuerKeysSupported",
[0x0088] = "NumberOfAliroEndpointKeysSupported",
[0xFFF9] = "AcceptedCommandList",
[0xFFFB] = "AttributeList",
[0xFFFC] = "FeatureMap",
}
local attr_name = attr_id_map[attr_id]
if attr_name ~= nil then
return self.attributes[attr_name]
end
return nil
end
function DoorLock:get_server_command_by_id(command_id)
local server_id_map = {
[0x0000] = "LockDoor",
[0x0001] = "UnlockDoor",
[0x0003] = "UnlockWithTimeout",
[0x000B] = "SetWeekDaySchedule",
[0x000C] = "GetWeekDaySchedule",
[0x000D] = "ClearWeekDaySchedule",
[0x000E] = "SetYearDaySchedule",
[0x000F] = "GetYearDaySchedule",
[0x0010] = "ClearYearDaySchedule",
[0x0011] = "SetHolidaySchedule",
[0x0012] = "GetHolidaySchedule",
[0x0013] = "ClearHolidaySchedule",
[0x001A] = "SetUser",
[0x001B] = "GetUser",
[0x001D] = "ClearUser",
[0x0022] = "SetCredential",
[0x0024] = "GetCredentialStatus",
[0x0026] = "ClearCredential",
[0x0027] = "UnboltDoor",
[0x0028] = "SetAliroReaderConfig",
[0x0029] = "ClearAliroReaderConfig",
}
if server_id_map[command_id] ~= nil then
return self.server.commands[server_id_map[command_id]]
end
return nil
end
function DoorLock:get_client_command_by_id(command_id)
local client_id_map = {
[0x000C] = "GetWeekDayScheduleResponse",
[0x000F] = "GetYearDayScheduleResponse",
[0x0012] = "GetHolidayScheduleResponse",
[0x001C] = "GetUserResponse",
[0x0023] = "SetCredentialResponse",
[0x0025] = "GetCredentialStatusResponse",
}
if client_id_map[command_id] ~= nil then
return self.client.commands[client_id_map[command_id]]
end
return nil
end
function DoorLock:get_event_by_id(event_id)
local event_id_map = {
[0x0000] = "DoorLockAlarm",
[0x0001] = "DoorStateChange",
[0x0002] = "LockOperation",
[0x0003] = "LockOperationError",
[0x0004] = "LockUserChange",
}
if event_id_map[event_id] ~= nil then
return self.server.events[event_id_map[event_id]]
end
return nil
end
DoorLock.attribute_direction_map = {
["LockState"] = "server",
["LockType"] = "server",
["ActuatorEnabled"] = "server",
["DoorState"] = "server",
["DoorOpenEvents"] = "server",
["DoorClosedEvents"] = "server",
["OpenPeriod"] = "server",
["NumberOfTotalUsersSupported"] = "server",
["NumberOfPINUsersSupported"] = "server",
["NumberOfRFIDUsersSupported"] = "server",
["NumberOfWeekDaySchedulesSupportedPerUser"] = "server",
["NumberOfYearDaySchedulesSupportedPerUser"] = "server",
["NumberOfHolidaySchedulesSupported"] = "server",
["MaxPINCodeLength"] = "server",
["MinPINCodeLength"] = "server",
["MaxRFIDCodeLength"] = "server",
["MinRFIDCodeLength"] = "server",
["CredentialRulesSupport"] = "server",
["NumberOfCredentialsSupportedPerUser"] = "server",
["Language"] = "server",
["LEDSettings"] = "server",
["AutoRelockTime"] = "server",
["SoundVolume"] = "server",
["OperatingMode"] = "server",
["SupportedOperatingModes"] = "server",
["DefaultConfigurationRegister"] = "server",
["EnableLocalProgramming"] = "server",
["EnableOneTouchLocking"] = "server",
["EnableInsideStatusLED"] = "server",
["EnablePrivacyModeButton"] = "server",
["LocalProgrammingFeatures"] = "server",
["WrongCodeEntryLimit"] = "server",
["UserCodeTemporaryDisableTime"] = "server",
["SendPINOverTheAir"] = "server",
["RequirePINforRemoteOperation"] = "server",
["ExpiringUserTimeout"] = "server",
["AliroReaderVerificationKey"] = "server",
["AliroReaderGroupIdentifier"] = "server",
["AliroReaderGroupSubIdentifier"] = "server",
["AliroExpeditedTransactionSupportedProtocolVersions"] = "server",
["AliroGroupResolvingKey"] = "server",
["AliroSupportedBLEUWBProtocolVersions"] = "server",
["AliroBLEAdvertisingVersion"] = "server",
["NumberOfAliroCredentialIssuerKeysSupported"] = "server",
["NumberOfAliroEndpointKeysSupported"] = "server",
["AcceptedCommandList"] = "server",
["AttributeList"] = "server",
["FeatureMap"] = "server",
}
do
local has_aliases, aliases = pcall(require, "st.matter.clusters.aliases.DoorLock.server.attributes")
if has_aliases then
for alias, _ in pairs(aliases) do
DoorLock.attribute_direction_map[alias] = "server"
end
end
end
DoorLock.command_direction_map = {
["LockDoor"] = "server",
["UnlockDoor"] = "server",
["UnlockWithTimeout"] = "server",
["SetWeekDaySchedule"] = "server",
["GetWeekDaySchedule"] = "server",
["ClearWeekDaySchedule"] = "server",
["SetYearDaySchedule"] = "server",
["GetYearDaySchedule"] = "server",
["ClearYearDaySchedule"] = "server",
["SetHolidaySchedule"] = "server",
["GetHolidaySchedule"] = "server",
["ClearHolidaySchedule"] = "server",
["SetUser"] = "server",
["GetUser"] = "server",
["ClearUser"] = "server",
["SetCredential"] = "server",
["GetCredentialStatus"] = "server",
["ClearCredential"] = "server",
["UnboltDoor"] = "server",
["SetAliroReaderConfig"] = "server",
["ClearAliroReaderConfig"] = "server",
["GetWeekDayScheduleResponse"] = "client",
["GetYearDayScheduleResponse"] = "client",
["GetHolidayScheduleResponse"] = "client",
["GetUserResponse"] = "client",
["SetCredentialResponse"] = "client",
["GetCredentialStatusResponse"] = "client",
}
do
local has_aliases, aliases = pcall(require, "st.matter.clusters.aliases.DoorLock.server.commands")
if has_aliases then
for alias, _ in pairs(aliases) do
DoorLock.command_direction_map[alias] = "server"
end
end
end
DoorLock.FeatureMap = DoorLock.types.Feature
function DoorLock.are_features_supported(feature, feature_map)
if (DoorLock.FeatureMap.bits_are_valid(feature)) then
return (feature & feature_map) == feature
end
return false
end
local attribute_helper_mt = {}
attribute_helper_mt.__index = function(self, key)
local direction = DoorLock.attribute_direction_map[key]
if direction == nil then
error(string.format("Referenced unknown attribute %s on cluster %s", key, DoorLock.NAME))
end
return DoorLock[direction].attributes[key]
end
DoorLock.attributes = {}
setmetatable(DoorLock.attributes, attribute_helper_mt)
local command_helper_mt = {}
command_helper_mt.__index = function(self, key)
local direction = DoorLock.command_direction_map[key]
if direction == nil then
error(string.format("Referenced unknown command %s on cluster %s", key, DoorLock.NAME))
end
return DoorLock[direction].commands[key]
end
DoorLock.commands = {}
setmetatable(DoorLock.commands, command_helper_mt)
local event_helper_mt = {}
event_helper_mt.__index = function(self, key)
return DoorLock.server.events[key]
end
DoorLock.events = {}
setmetatable(DoorLock.events, event_helper_mt)
setmetatable(DoorLock, {__index = cluster_base})
return DoorLock