Files
signalk-plugin/plugin/config/configManager.js
Giuseppe Raffa c2c1598226 feat: Implement rulesets and layout management for kiosk plugin
- Added rulesets manager to handle various data types and updates via HTTP and WebSocket.
- Introduced layout store for managing kiosk layouts with caching and server synchronization.
- Enhanced dashboard and data routes to support new layout and ruleset features.
- Updated kiosk HTML and JavaScript to utilize new layout rendering and data binding.
- Removed obsolete map route and integrated map functionality into the new tile renderer.
- Improved Telegram commands to reflect changes in data structure and logging.
- Refactored weather fetching intervals to prevent multiple instances.
- Added SSE stream for real-time layout updates in the kiosk.
2026-05-12 10:17:54 +02:00

83 lines
2.1 KiB
JavaScript

/**
* Gestore centralizzato della configurazione del plugin.
* Questa soluzione permette di leggere i valori di configurazione dinamicamente,
* quindi cambiano in tempo reale quando l'utente li modifica dalle impostazioni del plugin.
*/
let pluginOptions = {};
/**
* Inizializza il ConfigManager con le opzioni del plugin.
* Deve essere chiamato all'avvio del plugin.
* @param {Object} options - Le opzioni passate da Signal K al plugin
*/
function init(options) {
pluginOptions = options || {};
console.log('[CONFIG] ConfigManager inizializzato');
}
/**
* Ottiene il Telegram Bot Token
*/
function getTelegramToken() {
return process.env.TELEGRAM_BOT_TOKEN || '';
}
/**
* Ottiene il codice sensore
*/
function getSensorCode() {
return pluginOptions.sensor_code || '';
}
/**
* Ottiene l'id testuale del sensore (registrato sul server con POST /connect/new).
* Fallback su SENSOR_ID env per setup standalone.
*/
function getSensorId() {
return pluginOptions.sensor_id || process.env.SENSOR_ID || '';
}
/**
* @deprecated usa getSensorId. Mantenuto solo per retro-compatibilita'.
*/
function getSensorName() {
return getSensorId();
}
/**
* Ottiene l'intervallo di invio dati (in millisecondi, converte da secondi)
*/
function getSendInterval() {
const seconds = pluginOptions.sensor_interval || process.env.SEND_INTERVAL;
return (typeof seconds === 'number' ? seconds : parseInt(seconds)) * 1000 || 60000;
}
/**
* Ottiene il ritardo di riconnessione (in millisecondi, converte da secondi)
*/
function getReconnectDelay() {
const seconds = pluginOptions.reconnect_delay || process.env.RECONNECT_DELAY;
return (typeof seconds === 'number' ? seconds : parseInt(seconds)) * 1000 || 5000;
}
/**
* Ottiene un valore di configurazione generico
* @param {string} key - La chiave della configurazione
* @param {*} defaultValue - Il valore di default
*/
function get(key, defaultValue = null) {
return pluginOptions[key] !== undefined ? pluginOptions[key] : defaultValue;
}
module.exports = {
init,
getTelegramToken,
getSensorCode,
getSensorId,
getSensorName,
getSendInterval,
getReconnectDelay,
get
};