UNPKG

homebridge-apc-ups-alert

Version:

Provide information (and alerts) for apcupsd connected Uninterruptible Power Supplies

50 lines 2.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isServerConfiguration = exports.isBaseServerConfiguration = exports.isPluginConfiguration = void 0; const isPluginConfiguration = (x, logger = undefined) => { if (x.defaults !== undefined && !(0, exports.isBaseServerConfiguration)(x.defaults)) { logger === null || logger === void 0 ? void 0 : logger.error('Incorrect configuration: defaults are invalid.'); return false; } if (x.servers === undefined || !Array.isArray(x.servers) || x.servers.length === 0) { logger === null || logger === void 0 ? void 0 : logger.error('Incorrect configuration: servers must be an array of servers and contain at least one server.'); } for (const server of x.servers) { if (!(0, exports.isServerConfiguration)(server)) { logger === null || logger === void 0 ? void 0 : logger.error('Incorrect configuration: Entry for server is not correct: ' + JSON.stringify(server)); return false; } } return true; }; exports.isPluginConfiguration = isPluginConfiguration; // eslint-disable-next-line @typescript-eslint/no-explicit-any const isBaseServerConfiguration = (x) => { // Optional boolean exclude property if (x.interval !== undefined && typeof x.interval !== 'number') { return false; } // Optional low_battery_threshold property if (x.low_battery_threshold !== undefined && typeof x.low_battery_threshold !== 'number') { return false; } // Optional manufacturer name if (x.manufacturer !== undefined && (typeof x.manufacturer !== 'string' || x.manufacturer.length < 1)) { return false; } return true; }; exports.isBaseServerConfiguration = isBaseServerConfiguration; // eslint-disable-next-line @typescript-eslint/no-explicit-any const isServerConfiguration = (x) => { // Required host name if (x.host === undefined || typeof x.host !== 'string' || x.host.length < 1) { return false; } if (x.port !== undefined && typeof x.port !== 'number') { return false; } return (0, exports.isBaseServerConfiguration)(x); }; exports.isServerConfiguration = isServerConfiguration; //# sourceMappingURL=configModels.js.map