homebridge-tuya-laundry
Version:
Allows washer/dryer cycle completion notifications using Tuya smart plugs with power meter, now using local control.
54 lines • 2.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MessageGateway = void 0;
const pushGateway_1 = require("./pushGateway");
const telegramGateway_1 = require("./telegramGateway");
const ntfyGateway_1 = require("./ntfyGateway");
class MessageGateway {
constructor(log, config, api) {
var _a, _b, _c, _d;
this.log = log;
// Check if Telegram configuration is provided
if ((_b = (_a = config.notifications) === null || _a === void 0 ? void 0 : _a.telegram) === null || _b === void 0 ? void 0 : _b.botToken) {
log.info('Starting Telegram Gateway');
this.telegramGateway = new telegramGateway_1.TelegramGateway(config.notifications.telegram.botToken, log, api);
}
else {
log.warn('Telegram configuration is missing or incomplete. Telegram notifications are not available.');
}
// Check if Pushed.co configuration is provided
if ((_c = config.notifications) === null || _c === void 0 ? void 0 : _c.pushed) {
const { appKey, appSecret, channelAlias } = config.notifications.pushed;
if (appKey && appSecret && channelAlias) {
this.pushGateway = new pushGateway_1.PushGateway(log, config.notifications.pushed);
}
else {
log.warn('Incomplete Pushed.co configuration. Pushed.co notifications are not available.');
}
}
// Check if ntfy configuration is provided
if ((_d = config.notifications) === null || _d === void 0 ? void 0 : _d.ntfy) {
log.info('Starting ntfy Gateway');
this.ntfyGateway = new ntfyGateway_1.NtfyGateway(log, config.notifications.ntfy);
}
else {
log.warn('ntfy configuration is missing. ntfy notifications are not available.');
}
}
async send(message) {
if (this.pushGateway) {
this.pushGateway.send(message);
}
if (this.telegramGateway) {
await this.telegramGateway.send(message);
}
if (this.ntfyGateway) {
await this.ntfyGateway.send(message);
}
if (!this.pushGateway && !this.telegramGateway && !this.ntfyGateway) {
this.log.warn('No notification gateways configured. Message could not be sent:', message);
}
}
}
exports.MessageGateway = MessageGateway;
//# sourceMappingURL=messageGateway.js.map