@pst-on-npm/homebridge-enocean
Version:
Integrate EnOcean® devices into Homebridge.
47 lines • 1.89 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.HistoryServiceFactory = void 0;
const settings_1 = require("../settings");
class HistoryServiceFactory {
/**
* Assemble a unique name for the history data
* @param config The device config is used to assemble a unique name
*/
static getFilename(config) {
const filename = `${settings_1.PLATFORM_NAME}.EnOID_${config.devId.toString().replace(/:/g, '-')}.history.json`;
return filename;
}
/**
* Gets the option parameter for the fakegato history service
* @param config The device configuration to use
* @returns The optional parameter
*/
static getOptionalParams(api, config, log) {
const debug = process.env.DEBUG;
const isFakegatoDebug = debug && debug.toLocaleLowerCase().includes('homebridge-enocean-fakegato');
log.info(`${config.name}: fakegato debug log is ${isFakegatoDebug ? 'on' : 'off'}`);
return {
storage: 'fs',
path: api.user.persistPath(),
filename: this.getFilename(config),
log: isFakegatoDebug ? log : undefined,
};
}
/**
* Creates the fakegato history service
* @param platform
* @param accessory
* @param config
* @returns the service if configured or undefined
*/
static getOptionalHistoryService(platform, accessory, config, service = 'custom') {
if (platform.FakeGatoHistoryService) {
const optionalParams = this.getOptionalParams(platform.api, config, platform.log);
const historyService = new platform.FakeGatoHistoryService(service, accessory, optionalParams);
return historyService;
}
return undefined;
}
}
exports.HistoryServiceFactory = HistoryServiceFactory;
//# sourceMappingURL=HistoryServiceFactory.js.map