homebridge-tuya-laundry
Version:
Allows washer/dryer cycle completion notifications using Tuya smart plugs with power meter, now using local control.
51 lines • 2.15 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.IPCServer = void 0;
const net_1 = __importDefault(require("net"));
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const os_1 = __importDefault(require("os"));
const commandHandler_1 = require("./commandHandler");
class IPCServer {
constructor(log, config, tuyaApiService) {
this.log = log;
this.config = config;
this.tuyaApiService = tuyaApiService;
this.server = net_1.default.createServer();
this.socketPath = path_1.default.join(os_1.default.tmpdir(), 'tuya-laundry.sock');
this.commandHandler = new commandHandler_1.CommandHandler(this.tuyaApiService, this.log);
}
start() {
if (fs_1.default.existsSync(this.socketPath)) {
fs_1.default.unlinkSync(this.socketPath);
}
this.server = net_1.default.createServer((connection) => {
this.log.info('Connection received via IPC server');
this.commandHandler.showHelp(connection);
connection.write('> ');
connection.setEncoding('utf8');
connection.on('data', async (data) => {
const input = data.toString().trim();
this.log.info(`Command received via IPC: "${input}"`);
// Übergibt den Befehl an den CommandHandler zur Verarbeitung
await this.commandHandler.handleCommand(input, connection); // Jetzt mit der connection
});
});
this.server.listen(this.socketPath, () => {
this.log.info(`IPC server listening at ${this.socketPath}`);
});
this.server.on('error', (err) => {
this.log.error(`Error with IPC server: ${err.message}`);
});
}
stop() {
if (this.server) {
this.server.close(() => this.log.info('IPC server stopped.'));
}
}
}
exports.IPCServer = IPCServer;
//# sourceMappingURL=ipcServer.js.map