homebridge-cync-app 0.1.3 → 0.1.5
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.
- package/CHANGELOG.md +23 -11
- package/README.md +13 -20
- package/config.schema.json +2 -7
- package/dist/cync/config-client.d.ts +4 -0
- package/dist/cync/config-client.js +1 -0
- package/dist/cync/config-client.js.map +1 -1
- package/dist/cync/cync-client.d.ts +8 -7
- package/dist/cync/cync-client.js +31 -19
- package/dist/cync/cync-client.js.map +1 -1
- package/dist/cync/tcp-client.d.ts +10 -8
- package/dist/cync/tcp-client.js +63 -80
- package/dist/cync/tcp-client.js.map +1 -1
- package/dist/cync/token-store.d.ts +0 -4
- package/dist/cync/token-store.js +2 -10
- package/dist/cync/token-store.js.map +1 -1
- package/dist/platform.d.ts +1 -4
- package/dist/platform.js +29 -18
- package/dist/platform.js.map +1 -1
- package/homebridge-ui/public/index.html +171 -110
- package/homebridge-ui/server.js +38 -73
- package/package.json +3 -9
- package/src/cync/config-client.ts +6 -1
- package/src/cync/cync-client.ts +44 -26
- package/src/cync/tcp-client.ts +78 -111
- package/src/cync/token-store.ts +2 -11
- package/src/platform.ts +39 -20
package/src/platform.ts
CHANGED
|
@@ -41,7 +41,10 @@ interface CyncAccessoryContext {
|
|
|
41
41
|
*/
|
|
42
42
|
export class CyncAppPlatform implements DynamicPlatformPlugin {
|
|
43
43
|
public readonly accessories: PlatformAccessory[] = [];
|
|
44
|
-
|
|
44
|
+
public configureAccessory(accessory: PlatformAccessory): void {
|
|
45
|
+
this.log.info('Restoring cached accessory', accessory.displayName);
|
|
46
|
+
this.accessories.push(accessory);
|
|
47
|
+
}
|
|
45
48
|
private readonly log: Logger;
|
|
46
49
|
private readonly api: API;
|
|
47
50
|
private readonly config: PlatformConfig;
|
|
@@ -165,10 +168,26 @@ export class CyncAppPlatform implements DynamicPlatformPlugin {
|
|
|
165
168
|
this.api = api;
|
|
166
169
|
|
|
167
170
|
// Extract login config from platform config
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
171
|
+
const raw = this.config as Record<string, unknown>;
|
|
172
|
+
|
|
173
|
+
// Canonical config keys: username, password, twoFactor
|
|
174
|
+
// Accept legacy "email" as a fallback source for username, but do not write it back.
|
|
175
|
+
const username =
|
|
176
|
+
typeof raw.username === 'string'
|
|
177
|
+
? raw.username
|
|
178
|
+
: typeof raw.email === 'string'
|
|
179
|
+
? raw.email
|
|
180
|
+
: '';
|
|
181
|
+
|
|
182
|
+
const password =
|
|
183
|
+
typeof raw.password === 'string'
|
|
184
|
+
? raw.password
|
|
185
|
+
: '';
|
|
186
|
+
|
|
187
|
+
const twoFactor =
|
|
188
|
+
typeof raw.twoFactor === 'string'
|
|
189
|
+
? raw.twoFactor
|
|
190
|
+
: undefined;
|
|
172
191
|
|
|
173
192
|
const cyncLogger = toCyncLogger(this.log);
|
|
174
193
|
const tcpClient = new TcpClient(cyncLogger);
|
|
@@ -177,8 +196,8 @@ export class CyncAppPlatform implements DynamicPlatformPlugin {
|
|
|
177
196
|
new ConfigClient(cyncLogger),
|
|
178
197
|
tcpClient,
|
|
179
198
|
{
|
|
180
|
-
|
|
181
|
-
password
|
|
199
|
+
username,
|
|
200
|
+
password,
|
|
182
201
|
twoFactor,
|
|
183
202
|
},
|
|
184
203
|
this.api.user.storagePath(),
|
|
@@ -200,19 +219,21 @@ export class CyncAppPlatform implements DynamicPlatformPlugin {
|
|
|
200
219
|
});
|
|
201
220
|
}
|
|
202
221
|
|
|
203
|
-
/**
|
|
204
|
-
* Called when cached accessories are restored from disk.
|
|
205
|
-
*/
|
|
206
|
-
configureAccessory(accessory: PlatformAccessory): void {
|
|
207
|
-
this.log.info('Restoring cached accessory', accessory.displayName);
|
|
208
|
-
this.accessories.push(accessory);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
222
|
private async loadCync(): Promise<void> {
|
|
212
223
|
try {
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
const
|
|
224
|
+
const raw = this.config as Record<string, unknown>;
|
|
225
|
+
|
|
226
|
+
const username =
|
|
227
|
+
typeof raw.username === 'string'
|
|
228
|
+
? raw.username
|
|
229
|
+
: typeof raw.email === 'string'
|
|
230
|
+
? raw.email
|
|
231
|
+
: '';
|
|
232
|
+
|
|
233
|
+
const password =
|
|
234
|
+
typeof raw.password === 'string'
|
|
235
|
+
? raw.password
|
|
236
|
+
: '';
|
|
216
237
|
|
|
217
238
|
if (!username || !password) {
|
|
218
239
|
this.log.warn('Cync: credentials missing in config.json; skipping cloud login.');
|
|
@@ -237,7 +258,6 @@ export class CyncAppPlatform implements DynamicPlatformPlugin {
|
|
|
237
258
|
);
|
|
238
259
|
|
|
239
260
|
// Ask the CyncClient for the LAN login code derived from stored session.
|
|
240
|
-
// If it returns an empty blob, LAN is disabled but cloud still works.
|
|
241
261
|
let loginCode: Uint8Array = new Uint8Array();
|
|
242
262
|
try {
|
|
243
263
|
loginCode = this.client.getLanLoginCode();
|
|
@@ -254,7 +274,6 @@ export class CyncAppPlatform implements DynamicPlatformPlugin {
|
|
|
254
274
|
loginCode.length,
|
|
255
275
|
);
|
|
256
276
|
|
|
257
|
-
// ### 🧩 LAN Transport Bootstrap: wire frame listeners via CyncClient
|
|
258
277
|
await this.client.startTransport(cloudConfig, loginCode);
|
|
259
278
|
} else {
|
|
260
279
|
this.log.info(
|