From 68b02221909dbe98e26f55f5edb8ef02d5aaad10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Meireles?= Date: Tue, 18 Jan 2022 20:12:20 +0000 Subject: [PATCH] do not crash whole homebridge when we hit #90 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - and make things a bit more verbose in order to isolate root cause Signed-off-by: António Meireles --- src/platform.ts | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/src/platform.ts b/src/platform.ts index da106d0..dfd3863 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -127,28 +127,36 @@ class VieramaticPlatform implements DynamicPlatformPlugin { if (Abnormal(conn)) return conn const tv = conn.value - tv.specs.friendlyName = (device.friendlyName ?? tv.specs.friendlyName).trim() - const accessory = new this.api.platformAccessory( - tv.specs.friendlyName, - tv.specs.serialNumber, - this.api.hap.Categories.TELEVISION - ) + if (device.friendlyName) tv.specs.friendlyName = device.friendlyName + tv.specs.friendlyName = tv.specs.friendlyName.trim() + + try { + const accessory = new this.api.platformAccessory( + tv.specs.friendlyName, + tv.specs.serialNumber, + this.api.hap.Categories.TELEVISION + ) - accessory.context.device = tv + accessory.context.device = tv - const accessories = this.storage.accessories - const firstTime = isEmpty(accessories) || !accessories[tv.specs.serialNumber] + const accessories = this.storage.accessories + const firstTime = isEmpty(accessories) || !accessories[tv.specs.serialNumber] - if (firstTime) this.log.info(`Initializing '${tv.specs.friendlyName}' first time ever.`) + if (firstTime) this.log.info(`Initializing '${tv.specs.friendlyName}' first time ever.`) - if (!device.disabledAppSupport && Abnormal(tv.apps)) { - const err = `Unable to fetch Apps list from the TV: ${tv.apps.error.message}.` - const ft = `Unable to finish initial setup of ${tv.specs.friendlyName}. ${err}. This TV must be powered ON and NOT in stand-by.` - if (firstTime) return { error: Error(ft) } - this.log.debug(err) - } + if (!device.disabledAppSupport && Abnormal(tv.apps)) { + const err = `Unable to fetch Apps list from the TV: ${tv.apps.error.message}.` + const ft = `Unable to finish initial setup of ${tv.specs.friendlyName}. ${err}. This TV must be powered ON and NOT in stand-by.` + if (firstTime) return { error: Error(ft) } + this.log.debug(err) + } - return { value: new VieramaticPlatformAccessory(this, accessory, device) } + return { value: new VieramaticPlatformAccessory(this, accessory, device) } + } catch (error) { + this.log.error('device:', JSON.stringify(device)) + this.log.error('specs:', JSON.stringify(tv.specs)) + return { error: error as Error } + } } }