homebridge-tuya-laundry
Version:
Allows washer/dryer cycle completion notifications using Tuya smart plugs with power meter, now using local control.
41 lines • 2.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConfigManager = void 0;
class ConfigManager {
constructor(config) {
this.config = config;
}
getConfig() {
const { laundryDevices, tuyaApiCredentials, notifications } = this.config;
// Optional: Log a warning if no laundry devices are specified, but continue
if (!laundryDevices || laundryDevices.length === 0) {
console.warn('No laundry devices specified in the configuration. The plugin will start without monitoring any devices.');
}
// Check if Tuya API credentials are provided and contain necessary fields
if (!tuyaApiCredentials || !tuyaApiCredentials.accessId || !tuyaApiCredentials.accessKey ||
!tuyaApiCredentials.username || !tuyaApiCredentials.password ||
!tuyaApiCredentials.countryCode || !tuyaApiCredentials.appSchema ||
!tuyaApiCredentials.endpoint) {
throw new Error('Tuya API credentials and necessary fields (accessId, accessKey, username, password, countryCode, appSchema, endpoint) must be provided.');
}
console.log('Laundry Device Config:', this.config.laundryDevices);
// Validate device data if available
if (laundryDevices && laundryDevices.length > 0) {
laundryDevices.forEach((device) => {
const { deviceId, localKey, ipAddress } = device;
if (!deviceId || !localKey || !ipAddress) {
console.warn(`Device ${device.name || deviceId} is missing ID, Key, or IP Address and will not be monitored.`);
return;
}
});
}
// Return the configuration, including notifications if configured
return {
laundryDevices: laundryDevices || [],
tuyaApiCredentials,
notifications: notifications || {}, // Include notifications or default to an empty object if not provided
};
}
}
exports.ConfigManager = ConfigManager;
//# sourceMappingURL=configManager.js.map