homebridge-ttlock-accesscode 2.2.0-beta.0 → 2.2.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +38 -5
  2. package/config.schema.json +129 -20
  3. package/dist/api/dirigeraApi.d.ts +34 -0
  4. package/dist/api/dirigeraApi.js +127 -0
  5. package/dist/api/dirigeraApi.js.map +1 -0
  6. package/dist/api/ttlockApi.d.ts +8 -0
  7. package/dist/api/ttlockApi.js +20 -0
  8. package/dist/api/ttlockApi.js.map +1 -1
  9. package/dist/config.d.ts +32 -0
  10. package/dist/config.js +123 -1
  11. package/dist/config.js.map +1 -1
  12. package/dist/devices/accessoryInformation.d.ts +8 -2
  13. package/dist/devices/accessoryInformation.js.map +1 -1
  14. package/dist/devices/baseDevice.d.ts +3 -3
  15. package/dist/devices/baseDevice.js +4 -2
  16. package/dist/devices/baseDevice.js.map +1 -1
  17. package/dist/devices/descriptorHelpers.d.ts +1 -1
  18. package/dist/devices/descriptorHelpers.js +4 -1
  19. package/dist/devices/descriptorHelpers.js.map +1 -1
  20. package/dist/devices/deviceManager.d.ts +10 -0
  21. package/dist/devices/deviceManager.js +112 -0
  22. package/dist/devices/deviceManager.js.map +1 -1
  23. package/dist/devices/homekitDoor.d.ts +44 -0
  24. package/dist/devices/homekitDoor.js +218 -0
  25. package/dist/devices/homekitDoor.js.map +1 -0
  26. package/dist/devices/homekitLock.js +21 -7
  27. package/dist/devices/homekitLock.js.map +1 -1
  28. package/dist/platform.d.ts +16 -4
  29. package/dist/platform.js +19 -4
  30. package/dist/platform.js.map +1 -1
  31. package/dist/utils.js +4 -1
  32. package/dist/utils.js.map +1 -1
  33. package/homebridge-ui/public/app.js +1434 -0
  34. package/homebridge-ui/public/index.html +10 -0
  35. package/homebridge-ui/public/styles.css +417 -0
  36. package/homebridge-ui/server.js +122 -0
  37. package/package.json +14 -12
@@ -0,0 +1,10 @@
1
+ <link rel="stylesheet" href="./styles.css" />
2
+
3
+ <div id="app" class="ttlock-ui">
4
+ <div class="loading-panel">
5
+ <div class="spinner-border text-primary" role="status"></div>
6
+ <span>Loading TTLock setup...</span>
7
+ </div>
8
+ </div>
9
+
10
+ <script src="./app.js"></script>
@@ -0,0 +1,417 @@
1
+ :root {
2
+ --tt-bg: #f6f7f9;
3
+ --tt-panel: #ffffff;
4
+ --tt-border: #d9dee7;
5
+ --tt-border-strong: #b9c3d1;
6
+ --tt-text: #1f2937;
7
+ --tt-muted: #667085;
8
+ --tt-primary: #2563eb;
9
+ --tt-primary-dark: #1d4ed8;
10
+ --tt-success: #0f766e;
11
+ --tt-warning: #a16207;
12
+ --tt-danger: #b42318;
13
+ --tt-soft: #f8fafc;
14
+ }
15
+
16
+ * {
17
+ box-sizing: border-box;
18
+ }
19
+
20
+ .ttlock-ui {
21
+ background: var(--tt-bg);
22
+ color: var(--tt-text);
23
+ font-size: 14px;
24
+ line-height: 1.45;
25
+ min-height: 100%;
26
+ padding: 18px;
27
+ }
28
+
29
+ .loading-panel {
30
+ align-items: center;
31
+ color: var(--tt-muted);
32
+ display: flex;
33
+ gap: 12px;
34
+ justify-content: center;
35
+ min-height: 220px;
36
+ }
37
+
38
+ .ui-shell {
39
+ display: grid;
40
+ gap: 14px;
41
+ margin: 0 auto;
42
+ max-width: 1120px;
43
+ }
44
+
45
+ .topbar {
46
+ align-items: flex-start;
47
+ display: block;
48
+ }
49
+
50
+ .topbar h2 {
51
+ font-size: 22px;
52
+ font-weight: 650;
53
+ letter-spacing: 0;
54
+ line-height: 1.2;
55
+ margin: 0 0 4px;
56
+ }
57
+
58
+ .section-heading p,
59
+ .advanced-panel p,
60
+ .inline-note,
61
+ .field-note {
62
+ color: var(--tt-muted);
63
+ margin: 0;
64
+ }
65
+
66
+ .panel,
67
+ .item-card {
68
+ background: var(--tt-panel);
69
+ border: 1px solid var(--tt-border);
70
+ border-radius: 6px;
71
+ }
72
+
73
+ .panel {
74
+ padding: 18px;
75
+ }
76
+
77
+ .section-heading {
78
+ align-items: center;
79
+ display: grid;
80
+ gap: 12px;
81
+ grid-template-columns: minmax(0, 1fr) auto;
82
+ margin-bottom: 16px;
83
+ }
84
+
85
+ .section-heading h3 {
86
+ font-size: 17px;
87
+ font-weight: 650;
88
+ line-height: 1.25;
89
+ margin: 0 0 2px;
90
+ }
91
+
92
+ .field-grid {
93
+ display: grid;
94
+ gap: 14px;
95
+ grid-template-columns: repeat(2, minmax(0, 1fr));
96
+ }
97
+
98
+ .field-grid.single {
99
+ grid-template-columns: 1fr;
100
+ }
101
+
102
+ .polling-grid {
103
+ grid-template-columns: repeat(5, minmax(0, 1fr));
104
+ }
105
+
106
+ .field-grid .wide {
107
+ grid-column: 1 / -1;
108
+ }
109
+
110
+ .form-label {
111
+ color: #374151;
112
+ font-weight: 600;
113
+ margin-bottom: 6px;
114
+ }
115
+
116
+ .required-mark {
117
+ color: var(--tt-danger);
118
+ }
119
+
120
+ .form-control[readonly] {
121
+ background: #f3f6fa;
122
+ color: #344054;
123
+ }
124
+
125
+ .secret-value {
126
+ font-family: ui-monospace, SFMono-Regular, Consolas, 'Liberation Mono', monospace;
127
+ font-size: 12px;
128
+ }
129
+
130
+ .button-row {
131
+ display: flex;
132
+ flex-wrap: wrap;
133
+ gap: 10px;
134
+ margin-top: 14px;
135
+ }
136
+
137
+ .btn {
138
+ border-radius: 6px;
139
+ }
140
+
141
+ .btn-primary {
142
+ background: var(--tt-primary);
143
+ border-color: var(--tt-primary);
144
+ }
145
+
146
+ .btn-primary:hover,
147
+ .btn-primary:focus {
148
+ background: var(--tt-primary-dark);
149
+ border-color: var(--tt-primary-dark);
150
+ }
151
+
152
+ .status-pill {
153
+ align-items: center;
154
+ border-radius: 999px;
155
+ display: inline-flex;
156
+ font-size: 12px;
157
+ font-weight: 700;
158
+ padding: 5px 9px;
159
+ white-space: nowrap;
160
+ }
161
+
162
+ .status-pill.ready {
163
+ background: #e7f6f3;
164
+ color: var(--tt-success);
165
+ }
166
+
167
+ .status-pill.blocked {
168
+ background: #fff7ed;
169
+ color: var(--tt-warning);
170
+ }
171
+
172
+ .status-pill.neutral {
173
+ background: #eef2f7;
174
+ color: #475467;
175
+ }
176
+
177
+ .hub-list,
178
+ .door-list {
179
+ display: grid;
180
+ gap: 10px;
181
+ }
182
+
183
+ .item-card {
184
+ padding: 12px;
185
+ }
186
+
187
+ .item-header {
188
+ align-items: flex-start;
189
+ display: grid;
190
+ gap: 12px;
191
+ grid-template-columns: minmax(0, 1fr) auto;
192
+ margin-bottom: 12px;
193
+ }
194
+
195
+ .item-title {
196
+ font-weight: 700;
197
+ margin: 0 0 2px;
198
+ min-width: 0;
199
+ overflow-wrap: anywhere;
200
+ }
201
+
202
+ .item-title-row {
203
+ align-items: center;
204
+ display: flex;
205
+ flex-wrap: wrap;
206
+ gap: 8px;
207
+ }
208
+
209
+ .empty-state {
210
+ border: 1px dashed var(--tt-border-strong);
211
+ border-radius: 6px;
212
+ color: var(--tt-muted);
213
+ padding: 12px;
214
+ }
215
+
216
+ .subsection {
217
+ border-top: 1px solid var(--tt-border);
218
+ display: grid;
219
+ gap: 12px;
220
+ padding-top: 16px;
221
+ }
222
+
223
+ .subsection:first-of-type {
224
+ border-top: 0;
225
+ padding-top: 0;
226
+ }
227
+
228
+ .subsection + .subsection {
229
+ margin-top: 18px;
230
+ }
231
+
232
+ .subsection-header {
233
+ align-items: flex-start;
234
+ display: grid;
235
+ gap: 12px;
236
+ grid-template-columns: minmax(0, 1fr) auto;
237
+ }
238
+
239
+ .subsection-header h4 {
240
+ font-size: 15px;
241
+ font-weight: 700;
242
+ line-height: 1.25;
243
+ margin: 0 0 2px;
244
+ }
245
+
246
+ .hub-actions,
247
+ .door-command-row {
248
+ align-items: center;
249
+ display: flex;
250
+ flex-wrap: wrap;
251
+ gap: 8px;
252
+ }
253
+
254
+ .setup-card {
255
+ background: #ffffff;
256
+ }
257
+
258
+ .hub-grid {
259
+ grid-template-columns: 1fr;
260
+ }
261
+
262
+ .door-fields {
263
+ display: grid;
264
+ gap: 12px;
265
+ grid-template-columns: 1fr;
266
+ }
267
+
268
+ .advanced-panel {
269
+ padding: 0;
270
+ }
271
+
272
+ .advanced-panel > summary {
273
+ align-items: center;
274
+ cursor: pointer;
275
+ display: grid;
276
+ gap: 12px;
277
+ grid-template-columns: minmax(0, 1fr) auto;
278
+ list-style: none;
279
+ padding: 18px;
280
+ }
281
+
282
+ .advanced-panel > summary::-webkit-details-marker {
283
+ display: none;
284
+ }
285
+
286
+ .advanced-panel > summary::after {
287
+ color: var(--tt-muted);
288
+ content: 'Expand';
289
+ font-size: 12px;
290
+ font-weight: 700;
291
+ }
292
+
293
+ .advanced-panel[open] > summary::after {
294
+ content: 'Collapse';
295
+ }
296
+
297
+ .advanced-panel h3 {
298
+ font-size: 17px;
299
+ font-weight: 650;
300
+ line-height: 1.25;
301
+ margin: 0 0 2px;
302
+ }
303
+
304
+ .advanced-body {
305
+ border-top: 1px solid var(--tt-border);
306
+ padding: 18px;
307
+ }
308
+
309
+ .modal-backdrop-custom {
310
+ align-items: center;
311
+ background: rgb(15 23 42 / 0.46);
312
+ display: flex;
313
+ inset: 0;
314
+ justify-content: center;
315
+ padding: 18px;
316
+ position: fixed;
317
+ z-index: 2000;
318
+ }
319
+
320
+ .modal-panel {
321
+ background: var(--tt-panel);
322
+ border-radius: 6px;
323
+ box-shadow: 0 20px 48px rgb(15 23 42 / 0.22);
324
+ max-height: calc(100vh - 36px);
325
+ max-width: 720px;
326
+ overflow: auto;
327
+ width: 100%;
328
+ }
329
+
330
+ .modal-header-custom {
331
+ align-items: flex-start;
332
+ border-bottom: 1px solid var(--tt-border);
333
+ display: flex;
334
+ justify-content: space-between;
335
+ padding: 16px 18px;
336
+ }
337
+
338
+ .modal-header-custom h4 {
339
+ font-size: 18px;
340
+ font-weight: 650;
341
+ margin: 0;
342
+ }
343
+
344
+ .modal-body-custom {
345
+ padding: 18px;
346
+ }
347
+
348
+ .choice-grid {
349
+ display: grid;
350
+ gap: 10px;
351
+ }
352
+
353
+ .choice-button {
354
+ background: #ffffff;
355
+ border: 1px solid var(--tt-border);
356
+ border-radius: 6px;
357
+ padding: 12px;
358
+ text-align: left;
359
+ transition:
360
+ border-color 0.14s ease,
361
+ box-shadow 0.14s ease;
362
+ width: 100%;
363
+ }
364
+
365
+ .choice-button:hover,
366
+ .choice-button:focus {
367
+ border-color: var(--tt-primary);
368
+ box-shadow: 0 0 0 3px rgb(37 99 235 / 0.12);
369
+ }
370
+
371
+ .choice-title {
372
+ color: var(--tt-text);
373
+ display: block;
374
+ font-weight: 700;
375
+ margin-bottom: 3px;
376
+ }
377
+
378
+ .choice-meta {
379
+ color: var(--tt-muted);
380
+ display: block;
381
+ font-size: 12px;
382
+ }
383
+
384
+ .spinner-inline {
385
+ align-items: center;
386
+ display: inline-flex;
387
+ gap: 8px;
388
+ }
389
+
390
+ @media (max-width: 860px) {
391
+ .ttlock-ui {
392
+ padding: 12px;
393
+ }
394
+
395
+ .topbar,
396
+ .section-heading,
397
+ .item-header,
398
+ .subsection-header,
399
+ .door-fields {
400
+ align-items: stretch;
401
+ display: grid;
402
+ grid-template-columns: 1fr;
403
+ }
404
+
405
+ .field-grid,
406
+ .polling-grid,
407
+ .hub-grid {
408
+ grid-template-columns: 1fr;
409
+ }
410
+
411
+ .subsection-header .btn,
412
+ .hub-actions .btn,
413
+ .door-command-row .btn,
414
+ .button-row .btn {
415
+ width: 100%;
416
+ }
417
+ }
@@ -0,0 +1,122 @@
1
+ import path from 'node:path';
2
+ import { fileURLToPath, pathToFileURL } from 'node:url';
3
+ import { format } from 'node:util';
4
+
5
+ import { HomebridgePluginUiServer, RequestError } from '@homebridge/plugin-ui-utils';
6
+
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = path.dirname(__filename);
9
+
10
+ class StreamLogger {
11
+ info(...args) {
12
+ this.write(process.stdout, args);
13
+ }
14
+
15
+ warn(...args) {
16
+ this.write(process.stderr, args);
17
+ }
18
+
19
+ error(...args) {
20
+ this.write(process.stderr, args);
21
+ }
22
+
23
+ debug(...args) {
24
+ if (process.env.DEBUG) {
25
+ this.write(process.stdout, args);
26
+ }
27
+ }
28
+
29
+ write(stream, args) {
30
+ stream.write(`${format(...args)}\n`);
31
+ }
32
+ }
33
+
34
+ function requestError(message, status = 400) {
35
+ return new RequestError(message, { status });
36
+ }
37
+
38
+ function getRequiredString(payload, field, label) {
39
+ const value = String(payload?.[field] ?? '').trim();
40
+ if (!value) {
41
+ throw requestError(`${label} is required.`);
42
+ }
43
+ return value;
44
+ }
45
+
46
+ async function importBuiltModule(modulePath) {
47
+ const moduleFile = path.join(__dirname, '..', 'dist', ...modulePath);
48
+ try {
49
+ return await import(pathToFileURL(moduleFile).href);
50
+ } catch {
51
+ throw requestError(`Could not load ${modulePath.join('/')}. Run npm run build before using this setup action.`, 500);
52
+ }
53
+ }
54
+
55
+ async function createTTLockApi(payload) {
56
+ const clientId = getRequiredString(payload, 'clientId', 'TTLock Client ID');
57
+ const clientSecret = getRequiredString(payload, 'clientSecret', 'TTLock Client Secret');
58
+ const username = getRequiredString(payload, 'username', 'TTLock username');
59
+ const password = getRequiredString(payload, 'password', 'TTLock password');
60
+ const { TTLockApi } = await importBuiltModule(['api', 'ttlockApi.js']);
61
+ const api = new TTLockApi(new StreamLogger(), clientId, clientSecret);
62
+ await api.authenticate(username, password);
63
+ return api;
64
+ }
65
+
66
+ async function createDirigeraClient(payload) {
67
+ const gatewayIP = getRequiredString(payload, 'gatewayIP', 'DIRIGERA gateway IP');
68
+ const { createDirigeraClient } = await import('dirigera');
69
+
70
+ return createDirigeraClient({
71
+ gatewayIP,
72
+ accessToken: payload?.accessToken,
73
+ });
74
+ }
75
+
76
+ class TTLockAccessCodeUiServer extends HomebridgePluginUiServer {
77
+ constructor() {
78
+ super();
79
+
80
+ this.onRequest('/ttlock-test-auth', this.testTTLockAuth.bind(this));
81
+ this.onRequest('/ttlock-locks', this.listTTLockLocks.bind(this));
82
+ this.onRequest('/dirigera-authenticate', this.authenticateDirigera.bind(this));
83
+ this.onRequest('/dirigera-open-close-sensors', this.listDirigeraOpenCloseSensors.bind(this));
84
+
85
+ this.ready();
86
+ }
87
+
88
+ async testTTLockAuth(payload) {
89
+ await createTTLockApi(payload);
90
+ return { ok: true };
91
+ }
92
+
93
+ async listTTLockLocks(payload) {
94
+ const api = await createTTLockApi(payload);
95
+ return api.listLocksForSetup();
96
+ }
97
+
98
+ async authenticateDirigera(payload) {
99
+ const client = await createDirigeraClient(payload);
100
+ const accessToken = await client.authenticate({ verbose: false });
101
+ return { accessToken };
102
+ }
103
+
104
+ async listDirigeraOpenCloseSensors(payload) {
105
+ const accessToken = getRequiredString(payload, 'accessToken', 'DIRIGERA access token');
106
+ const client = await createDirigeraClient({ ...payload, accessToken });
107
+ const sensors = await client.openCloseSensors.list();
108
+
109
+ return sensors.map((sensor) => ({
110
+ batteryPercentage: sensor.attributes?.batteryPercentage,
111
+ id: sensor.id,
112
+ isOpen: sensor.attributes?.isOpen,
113
+ isReachable: Boolean(sensor.isReachable),
114
+ manufacturer: sensor.attributes?.manufacturer || '',
115
+ model: sensor.attributes?.model || '',
116
+ name: sensor.attributes?.customName || sensor.attributes?.model || sensor.id,
117
+ roomName: sensor.room?.name || '',
118
+ }));
119
+ }
120
+ }
121
+
122
+ new TTLockAccessCodeUiServer();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Homebridge TTLock Access Code",
3
3
  "name": "homebridge-ttlock-accesscode",
4
- "version": "2.2.0-beta.0",
4
+ "version": "2.2.0-beta.2",
5
5
  "description": "Plugin that uses TTLock Cloud API to communicate with TTLock Devices connected to the G2 Gateway.",
6
6
  "license": "MIT",
7
7
  "type": "module",
@@ -13,16 +13,16 @@
13
13
  "url": "https://github.com/ZeliardM/homebridge-ttlock-accesscode/issues"
14
14
  },
15
15
  "engines": {
16
- "homebridge": "^1.8.0 || ^2.0.0-beta.0",
17
- "node": "^20 || ^22 || ^24"
16
+ "homebridge": "^1.11.2 || ^2.0.0",
17
+ "node": "^22 || ^24"
18
18
  },
19
19
  "publishConfig": {
20
20
  "access": "public"
21
21
  },
22
22
  "main": "dist/index.js",
23
23
  "scripts": {
24
- "build": "npm ci && rimraf -I ./dist && tsc",
25
- "lint": "eslint src/**/*.ts --max-warnings=0",
24
+ "build": "rimraf -I ./dist && tsc",
25
+ "lint": "eslint src/**/*.ts homebridge-ui/**/*.js --max-warnings=0",
26
26
  "prepublishOnly": "npm run lint && npm run build",
27
27
  "test": "echo \"No test specified\" && exit 0",
28
28
  "watch": "npm run build && npm link && nodemon"
@@ -44,20 +44,20 @@
44
44
  "files": [
45
45
  "config.schema.json",
46
46
  "dist",
47
+ "homebridge-ui",
47
48
  "LICENSE"
48
49
  ],
49
50
  "devDependencies": {
50
- "@eslint/eslintrc": "3.3.5",
51
51
  "@eslint/js": "^10.0.1",
52
52
  "@stylistic/eslint-plugin": "^5.10.0",
53
- "@types/node": "^25.6.0",
54
- "eslint": "^10.2.1",
55
- "homebridge": "^2.0.0-beta.101",
53
+ "@types/node": "^25.9.1",
54
+ "eslint": "^10.4.0",
55
+ "homebridge": "^2.0.2",
56
56
  "nodemon": "^3.1.14",
57
57
  "rimraf": "^6.1.3",
58
58
  "ts-node": "^10.9.2",
59
59
  "typescript": "^6.0.3",
60
- "typescript-eslint": "^8.59.0"
60
+ "typescript-eslint": "^8.59.4"
61
61
  },
62
62
  "homepage": "https://github.com/ZeliardM/homebridge-ttlock-accesscode#readme",
63
63
  "funding": [
@@ -71,8 +71,10 @@
71
71
  }
72
72
  ],
73
73
  "dependencies": {
74
- "axios": "^1.15.2",
75
- "ber-tlv": "^0.9.2"
74
+ "@homebridge/plugin-ui-utils": "^2.2.3",
75
+ "axios": "^1.16.1",
76
+ "ber-tlv": "^0.9.2",
77
+ "dirigera": "^1.8.0"
76
78
  },
77
79
  "overrides": {
78
80
  "node-persist": "^4.0.4"