Skip to content

Commit

Permalink
do not crash whole homebridge when we hit #90
Browse files Browse the repository at this point in the history
- and make things a bit more verbose in order to isolate root cause

Signed-off-by: António Meireles <antonio.meireles@reformi.st>
  • Loading branch information
AntonioMeireles committed Jan 18, 2022
1 parent df01c6b commit 68b0222
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}
}

Expand Down

0 comments on commit 68b0222

Please sign in to comment.