Fix some data browser errors
This commit is contained in:
@@ -78,9 +78,14 @@ class MPPTReader extends EventEmitter {
|
||||
// Istanzia gli MPPT configurati (indicizzati per nome logico)
|
||||
this.mppts = new Map();
|
||||
for (const config of mppts) {
|
||||
const normalizedAddress = Number(config.address);
|
||||
if (!config.id || !Number.isFinite(normalizedAddress)) {
|
||||
this.log(`[reader] configurazione MPPT ignorata perche' incompleta: ${JSON.stringify(config)}`);
|
||||
continue;
|
||||
}
|
||||
const mppt = new MPPT({
|
||||
name: config.id,
|
||||
address: config.address,
|
||||
address: normalizedAddress,
|
||||
log: this.log,
|
||||
});
|
||||
this.mppts.set(config.id, mppt);
|
||||
|
||||
19
src/index.js
19
src/index.js
@@ -228,14 +228,27 @@ module.exports = function (app) {
|
||||
}
|
||||
|
||||
function normalizeOptions(options = {}) {
|
||||
const configuredMppts = Array.isArray(options.mppts) && options.mppts.length > 0
|
||||
? options.mppts
|
||||
: defaultPluginOptions.mppts;
|
||||
const normalizedMppts = configuredMppts.map((configuredMppt, index) => {
|
||||
const defaultMppt = defaultPluginOptions.mppts[index] || defaultPluginOptions.mppts[0];
|
||||
const normalizedAddress = Number(configuredMppt.address);
|
||||
|
||||
return {
|
||||
// Identificativo SignalK del controller; se manca si usa il default per indice.
|
||||
id: configuredMppt.id || defaultMppt.id,
|
||||
// Indirizzo UART/DST del controller; evita polling con address=undefined.
|
||||
address: Number.isFinite(normalizedAddress) ? normalizedAddress : defaultMppt.address,
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
device: options.device || defaultPluginOptions.device,
|
||||
baudRate: Number(options.baudRate || defaultPluginOptions.baudRate),
|
||||
publishIntervalMs: Number(options.publishIntervalMs || defaultPluginOptions.publishIntervalMs),
|
||||
pollIntervalMs: Number(options.pollIntervalMs || defaultPluginOptions.pollIntervalMs),
|
||||
mppts: Array.isArray(options.mppts) && options.mppts.length > 0
|
||||
? options.mppts
|
||||
: defaultPluginOptions.mppts,
|
||||
mppts: normalizedMppts,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user