@petro-kushchak/homebridge-ch-gree-ac-eve-platform
Version:
Cooper&Hunter (based on Gree AC API) AC plugin for Homebridge (Homekit) with Web Hook/MQTT Data Sharing
77 lines • 3.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isMqttSensor = exports.isMqttConfiguration = exports.isDeviceConfiguration = exports.isPluginConfiguration = void 0;
const isPluginConfiguration = (x, logger = undefined) => {
if (x.mqtt === undefined || !(0, exports.isMqttConfiguration)(x.mqtt)) {
logger === null || logger === void 0 ? void 0 : logger.error('Incorrect configuration: mqtt does not contain required fields');
return false;
}
if (x.broadcastAddress === undefined) {
logger === null || logger === void 0 ? void 0 : logger.error('Incorrect configuration: broadcastAddress configuration is invalid: ' + JSON.stringify(x.broadcastAddress));
}
if (x.broadcastAddress === undefined) {
logger === null || logger === void 0 ? void 0 : logger.error('Incorrect configuration: broadcastAddress is invalid: ' + JSON.stringify(x.broadcastAddress));
return false;
}
if (x.coolingMinTemp === undefined) {
logger === null || logger === void 0 ? void 0 : logger.error('Incorrect configuration: coolingMinTemp is invalid: ' + JSON.stringify(x.coolingMinTemp));
return false;
}
if (x.heatingMinTemp === undefined) {
logger === null || logger === void 0 ? void 0 : logger.error('Incorrect configuration: heatingMinTemp is invalid: ' + JSON.stringify(x.heatingMinTemp));
return false;
}
if (x.heatingMaxTemp === undefined) {
logger === null || logger === void 0 ? void 0 : logger.error('Incorrect configuration: heatingMaxTemp is invalid: ' + JSON.stringify(x.heatingMaxTemp));
return false;
}
if (x.httpPort !== undefined && typeof x.httpPort !== 'number') {
logger === null || logger === void 0 ? void 0 : logger.error('Incorrect configuration: httpPort is invalid: ' + JSON.stringify(x.httpPort));
return false;
}
if (x.devices !== undefined) {
return hasValidDeviceConfigurations(x.devices, logger);
}
return true;
};
exports.isPluginConfiguration = isPluginConfiguration;
function hasValidDeviceConfigurations(devices, logger) {
if (devices !== undefined) {
if (!Array.isArray(devices)) {
logger === null || logger === void 0 ? void 0 : logger.error('Incorrect configuration: devices must be an array');
return false;
}
for (const element of devices) {
if (!(0, exports.isDeviceConfiguration)(element)) {
logger === null || logger === void 0 ? void 0 : logger.error('Incorrect configuration: Entry for device is not correct: ' + JSON.stringify(element));
return false;
}
}
}
return true;
}
const isDeviceConfiguration = (x) => {
// Required id property
if (x.id === undefined || typeof x.id !== 'string' || x.id.length < 1) {
return false;
}
// Required sensorTopic property
if (x.sensorTopic === undefined || typeof x.sensorTopic !== 'string' || x.sensorTopic.length < 1) {
return false;
}
return true;
};
exports.isDeviceConfiguration = isDeviceConfiguration;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const isMqttConfiguration = (x) => x.base_topic !== undefined &&
typeof x.base_topic === 'string' &&
x.base_topic.length > 0 &&
x.server !== undefined &&
typeof x.server === 'string' &&
x.server.length > 0;
exports.isMqttConfiguration = isMqttConfiguration;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const isMqttSensor = (x, temperatureKey) => (x[temperatureKey] !== undefined) &&
typeof x[temperatureKey] === 'number';
exports.isMqttSensor = isMqttSensor;
//# sourceMappingURL=configModel.js.map