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/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 cfg = this.config as Record<string, unknown>;
169
- const username = (cfg.username ?? cfg.email) as string | undefined;
170
- const password = cfg.password as string | undefined;
171
- const twoFactor = cfg.twoFactor as string | undefined;
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
- email: username ?? '',
181
- password: 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 cfg = this.config as Record<string, unknown>;
214
- const username = (cfg.username ?? cfg.email) as string | undefined;
215
- const password = cfg.password as string | undefined;
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(