Skip to content

Commit

Permalink
chore: Dump module config on init/configUpdated to assist in debuggin…
Browse files Browse the repository at this point in the history
…g logs from the field.
  • Loading branch information
jswalden committed May 23, 2024
1 parent 95ac435 commit 931c29e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,27 @@ export class PtzOpticsInstance extends InstanceBase<PtzOpticsConfig> {
this.#visca.close()
}

/**
* Write a copy of the given module config information to logs.
*
* @param config
* The config information to log.
* @param desc
* A description of the event occasioning the logging.
*/
logConfig(config: PtzOpticsConfig, desc = 'logConfig()'): void {
this.log(
'info',
`PTZOptics module configuration on ${desc}: ${JSON.stringify(config, (_k, v) => {
if (v === undefined) return { undefined: true }
return v
})}`
)
}

async init(config: PtzOpticsConfig): Promise<void> {
this.logConfig(config, 'init()')

this.#config = config

this.setActionDefinitions(getActions(this))
Expand All @@ -157,6 +177,8 @@ export class PtzOpticsInstance extends InstanceBase<PtzOpticsConfig> {
}

async configUpdated(config: PtzOpticsConfig): Promise<void> {
this.logConfig(config, 'configUpdated()')

// Reset the connection if the connection is closed or any configuration
// changed.
const resetConnection =
Expand Down

0 comments on commit 931c29e

Please # to comment.