Skip to content

Commit

Permalink
harden offline initialization in order to get rid of #90
Browse files Browse the repository at this point in the history
Signed-off-by: António Meireles <antonio.meireles@reformi.st>
  • Loading branch information
AntonioMeireles committed Jan 19, 2022
1 parent c91d91f commit 128626b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ class VieramaticPlatform implements DynamicPlatformPlugin {

return { value: new VieramaticPlatformAccessory(this, accessory, device) }
} catch (error) {
this.log.error('device:', JSON.stringify(device))
this.log.error('specs:', JSON.stringify(tv.specs))
this.log.error('device:', JSON.stringify(device, undefined, 2))
this.log.error('specs:', JSON.stringify(tv.specs, undefined, 2))
return { error: error as Error }
}
}
Expand Down
19 changes: 14 additions & 5 deletions src/viera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,23 @@ class VieraTV implements VieraTV {
tv.specs = await tv.#getSpecs()
settings.bootstrap ??= false
if (!settings.bootstrap) {
if (isEmpty(tv.specs) && settings.cached) {
if (isEmpty(tv.specs) && settings.cached && !isEmpty(settings.cached)) {
tv.log.warn(`Unable to fetch specs from TV at '${ip}'.`)
tv.log.warn('Using the previously cached ones:\n\n', JSON.stringify(settings.cached))
if (settings.cached.requiresEncryption) {
const err = `IGNORING '${ip}' as we do not support offline initialization, from cache, for models that require encryption.`
return { error: Error(err) }
const err = `IGNORING '${ip}' as we do not support offline initialization, from cache, for models that require encryption.`
if (settings.cached.requiresEncryption) return { error: Error(err) }

tv.specs = settings.cached
}
if (isEmpty(tv.specs)) {
tv.log.error(
'please fill a bug at https://github.com/AntonioMeireles/homebridge-vieramatic/issues with data bellow'
)
return {
error: Error(
`${ip}: offline initialization failure!\n${JSON.stringify(settings, undefined, 2)}`
)
}
tv.specs ??= settings.cached
}

if (tv.specs.requiresEncryption) {
Expand Down

0 comments on commit 128626b

Please sign in to comment.