From 931c29ef31504e1e48c49508141c5b1d68bcf09e Mon Sep 17 00:00:00 2001 From: Jeff Walden Date: Wed, 22 May 2024 15:23:21 -0700 Subject: [PATCH] chore: Dump module config on init/configUpdated to assist in debugging logs from the field. --- src/instance.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/instance.ts b/src/instance.ts index ea986af..4df0a58 100644 --- a/src/instance.ts +++ b/src/instance.ts @@ -132,7 +132,27 @@ export class PtzOpticsInstance extends InstanceBase { 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 { + this.logConfig(config, 'init()') + this.#config = config this.setActionDefinitions(getActions(this)) @@ -157,6 +177,8 @@ export class PtzOpticsInstance extends InstanceBase { } async configUpdated(config: PtzOpticsConfig): Promise { + this.logConfig(config, 'configUpdated()') + // Reset the connection if the connection is closed or any configuration // changed. const resetConnection =