From 55eaf0a2de830da3a992bc48d8ed2d4f79004030 Mon Sep 17 00:00:00 2001 From: Steven Roebert Date: Sun, 27 Jul 2025 00:41:37 +0200 Subject: [PATCH] Moved pipe function to also pipe for faked serial ports --- lib/rfxcom.js | 4 ++++ package-lock.json | 4 ++-- test/helper.js | 5 +++++ test/rfxcom.spec.js | 8 ++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/rfxcom.js b/lib/rfxcom.js index f90fea7..325f4ea 100644 --- a/lib/rfxcom.js +++ b/lib/rfxcom.js @@ -291,6 +291,10 @@ class RfxCom extends EventEmitter { lock: false, autoOpen: false }); + } + + // Make sure all data is piped to the parser (also for faked serialports) + if (typeof self.serialport.pipe === "function") { self.serialport.pipe(self.parser); } diff --git a/package-lock.json b/package-lock.json index b7faf8f..2bf6c95 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rfxcom", - "version": "2.5.0", + "version": "2.6.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "rfxcom", - "version": "2.5.0", + "version": "2.6.2", "license": "MIT", "dependencies": { "date-format": "^4.0.14", diff --git a/test/helper.js b/test/helper.js index 47692c5..39cd72d 100644 --- a/test/helper.js +++ b/test/helper.js @@ -8,6 +8,7 @@ class FakeSerialPort extends events.EventEmitter { this.bytesWritten = []; this.flushed = false; this.isOpen = true; + this.pipeDestination = undefined; } write(buffer, callback) { @@ -18,6 +19,10 @@ class FakeSerialPort extends events.EventEmitter { } }; + pipe(destination) { + this.pipeDestination = destination; + } + flush(callback) { this.flushed = true; if (callback && typeof callback === "function") { diff --git a/test/rfxcom.spec.js b/test/rfxcom.spec.js index a0ee353..935add3 100644 --- a/test/rfxcom.spec.js +++ b/test/rfxcom.spec.js @@ -640,6 +640,14 @@ describe("RfxCom", function() { }); }); }); + it(".open should pipe data from the fake serialport to the parser", function() { + const fakeSerialPort = new FakeSerialPort(), + device = new rfxcom.RfxCom("/", { + port: fakeSerialPort + }); + device.open(); + expect(fakeSerialPort.pipeDestination).toBe(device.parser); + }); describe(".bytesToUint48", function() { it("should convert a sequence of 6 bytes to a longint", function() { expect(rfxcom.RfxCom.bytesToUint48([0xF1, 0x27, 0xba, 0x67, 0x28, 0x97])).toBe(265152933341335);