Skip to content

Commit

Permalink
Revert "Bump serialport to 10.5.0 (#607)"
Browse files Browse the repository at this point in the history
This reverts commit 9337083.
  • Loading branch information
Koenkk committed Jan 6, 2023
1 parent 0a06211 commit 022136a
Show file tree
Hide file tree
Showing 10 changed files with 1,487 additions and 837 deletions.
2,171 changes: 1,423 additions & 748 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@
}
],
"dependencies": {
"@serialport/bindings-cpp": "^10.8.0",
"@serialport/parser-delimiter": "^10.5.0",
"@serialport/stream": "^10.5.0",
"debounce": "^1.2.1",
"debug": "^4.3.4",
"fast-deep-equal": "^3.1.3",
"mixin-deep": "^2.0.1",
"mz": "^2.7.0",
"serialport": "9.2.8",
"slip": "^1.0.2"
},
"deprecated": false,
Expand All @@ -50,6 +48,7 @@
"@types/mz": "^2.7.4",
"@types/nedb": "*",
"@types/node": "*",
"@types/serialport": "*",
"@typescript-eslint/eslint-plugin": "*",
"@typescript-eslint/parser": "*",
"babel-jest": "*",
Expand Down
4 changes: 2 additions & 2 deletions src/adapter/deconz/driver/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
/* eslint-disable */
import Debug from 'debug';
import events from 'events';
import SerialPort from 'serialport';
import Writer from './writer';
import Parser from './parser';
import Frame from './frame';
import PARAM from './constants';
import * as Events from '../../events';
import {SerialPort} from '../../serialPort';
import SerialPortUtils from '../../serialPortUtils';
import SocketPortUtils from '../../socketPortUtils';
import net from 'net';
Expand Down Expand Up @@ -184,7 +184,7 @@ class Driver extends events.EventEmitter {

public openSerialPort(): Promise<void> {
debug(`Opening with ${this.path}`);
this.serialPort = new SerialPort({path: this.path, baudRate: 38400, autoOpen: false});
this.serialPort = new SerialPort(this.path, {baudRate: 38400, autoOpen: false});

this.writer = new Writer();
// @ts-ignore
Expand Down
7 changes: 3 additions & 4 deletions src/adapter/ezsp/driver/uart.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* istanbul ignore file */
import {EventEmitter} from 'events';
import SerialPort from 'serialport';
import net from 'net';
import {SerialPort} from '../../serialPort';
import SocketPortUtils from '../../socketPortUtils';
import {Deferred, crc16ccitt} from './utils';
import {Queue, Waitress} from '../../../utils';
Expand Down Expand Up @@ -67,14 +67,13 @@ export class SerialDriver extends EventEmitter {

private async openSerialPort(path: string, opt: Record<string, number|boolean>): Promise<void> {
const options = {
path,
baudRate: typeof opt.baudRate === 'number' ? opt.baudRate : 115200,
rtscts: typeof opt.rtscts === 'boolean' ? opt.rtscts : false,
autoOpen: false
};

debug(`Opening SerialPort with ${JSON.stringify(options)}`);
this.serialPort = new SerialPort(options);
debug(`Opening SerialPort with ${path} and ${JSON.stringify(options)}`);
this.serialPort = new SerialPort(path, options);

this.writer = new Writer();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down
23 changes: 0 additions & 23 deletions src/adapter/serialPort.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/adapter/serialPortUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {SerialPort} from './serialPort';
import SerialPort from 'serialport';
import {EqualsPartial} from '../utils';

interface PortInfoMatch {
Expand All @@ -23,4 +23,4 @@ async function is(path: string, matchers: PortInfoMatch[]): Promise<boolean> {
return matchers.find((matcher) => EqualsPartial(device, matcher)) != null;
}

export default {is, find};
export default {is, find};
8 changes: 4 additions & 4 deletions src/adapter/z-stack/znp/znp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {

import {Wait, Queue, Waitress, RealpathSync} from '../../../utils';

import {SerialPort} from '../../serialPort';
import SerialPortUtils from '../../serialPortUtils';
import SocketPortUtils from '../../socketPortUtils';

Expand All @@ -16,6 +15,7 @@ import ZpiObject from './zpiObject';
import {ZpiObjectPayload} from './tstype';
import {Subsystem, Type} from '../unpi/constants';

import SerialPort from 'serialport';
import net from 'net';
import events from 'events';
import Equals from 'fast-deep-equal/es6';
Expand Down Expand Up @@ -126,10 +126,10 @@ class Znp extends events.EventEmitter {
}

private async openSerialPort(): Promise<void> {
const options = {path: this.path, baudRate: this.baudRate, rtscts: this.rtscts, autoOpen: false};
const options = {baudRate: this.baudRate, rtscts: this.rtscts, autoOpen: false};

debug.log(`Opening SerialPort with ${JSON.stringify(options)}`);
this.serialPort = new SerialPort(options);
debug.log(`Opening SerialPort with ${this.path} and ${JSON.stringify(options)}`);
this.serialPort = new SerialPort(this.path, options);

this.unpiWriter = new UnpiWriter();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down
10 changes: 4 additions & 6 deletions src/adapter/zigate/driver/zigate.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* istanbul ignore file */
/* eslint-disable */

import {DelimiterParser} from '@serialport/parser-delimiter'
import SerialPort from 'serialport';
import {EventEmitter} from 'events';
import {Debug} from '../debug';
import {SerialPort} from '../../serialPort';
import SerialPortUtils from "../../serialPortUtils";
import SocketPortUtils from "../../socketPortUtils";
import net from "net";
Expand Down Expand Up @@ -203,8 +202,7 @@ export default class ZiGate extends EventEmitter {
}

private async openSerialPort(): Promise<void> {
this.serialPort = new SerialPort({
path: this.path,
this.serialPort = new SerialPort(this.path, {
baudRate: this.baudRate,
dataBits: 8,
parity: 'none', /* one of ['none', 'even', 'mark', 'odd', 'space'] */
Expand All @@ -213,7 +211,7 @@ export default class ZiGate extends EventEmitter {
autoOpen: false
});
this.parser = this.serialPort.pipe(
new DelimiterParser(
new SerialPort.parsers.Delimiter(
{delimiter: [ZiGateFrame.STOP_BYTE], includeDelimiter: true}
),
);
Expand Down Expand Up @@ -253,7 +251,7 @@ export default class ZiGate extends EventEmitter {


this.parser = this.socketPort.pipe(
new DelimiterParser({delimiter: [ZiGateFrame.STOP_BYTE], includeDelimiter: true}),
new SerialPort.parsers.Delimiter({delimiter: [ZiGateFrame.STOP_BYTE], includeDelimiter: true}),
);
this.parser.on('data', this.onSerialData.bind(this));

Expand Down
41 changes: 20 additions & 21 deletions test/adapter/ezsp/uart.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "regenerator-runtime/runtime";
import {SerialPort} from '../../../src/adapter/serialPort';
import SerialPort from 'serialport';
import {SerialDriver} from '../../../src/adapter/ezsp/driver/uart';
import {Writer} from '../../../src/adapter/ezsp/driver/writer';

Expand All @@ -18,24 +18,22 @@ const mockSerialPortWrite = jest.fn((buffer, cb) => (cb) ? cb() : null);
let mockSerialPortIsOpen = false;


jest.mock('../../../src/adapter/serialPort', () => {
return {
SerialPort: jest.fn().mockImplementation(() => {
return {
close: mockSerialPortClose,
constructor: mockSerialPortConstructor,
emit: () => {},
on: () => {},
once: mockSerialPortOnce,
open: mockSerialPortOpen,
pipe: mockSerialPortPipe,
set: mockSerialPortSet,
write: mockSerialPortWrite,
flush: mockSerialPortFlush,
isOpen: mockSerialPortIsOpen,
};
})
};
jest.mock('serialport', () => {
return jest.fn().mockImplementation(() => {
return {
close: mockSerialPortClose,
constructor: mockSerialPortConstructor,
emit: () => {},
on: () => {},
once: mockSerialPortOnce,
open: mockSerialPortOpen,
pipe: mockSerialPortPipe,
set: mockSerialPortSet,
write: mockSerialPortWrite,
flush: mockSerialPortFlush,
isOpen: mockSerialPortIsOpen,
};
});
});

let writeBufferSpy;
Expand Down Expand Up @@ -81,7 +79,8 @@ describe('UART', () => {

expect(SerialPort).toHaveBeenCalledTimes(1);
expect(SerialPort).toHaveBeenCalledWith(
{"path": "/dev/ttyACM0", "autoOpen": false, "baudRate": 115200, "rtscts": false},
"/dev/ttyACM0",
{"autoOpen": false, "baudRate": 115200, "rtscts": false},
);

expect(mockSerialPortPipe).toHaveBeenCalledTimes(1);
Expand All @@ -107,4 +106,4 @@ describe('UART', () => {
serialDriver.sendDATA(Buffer.from([1,2,3]));
expect(writeBufferSpy).toHaveBeenCalledTimes(9);
});
});
});
51 changes: 27 additions & 24 deletions test/adapter/z-stack/znp.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "regenerator-runtime/runtime";
import {Znp, ZpiObject} from '../../../src/adapter/z-stack/znp';
import {SerialPort} from '../../../src/adapter/serialPort';
import SerialPort from 'serialport';
import net from 'net';
import {Frame as UnpiFrame, Constants as UnpiConstants} from '../../../src/adapter/z-stack/unpi';
import {duplicateArray, ieeeaAddr1, ieeeaAddr2} from '../../testUtils';
Expand All @@ -21,24 +21,22 @@ jest.mock('../../../src/utils/wait', () => {
return jest.fn();
});

jest.mock('../../../src/adapter/serialPort', () => {
return {
SerialPort: jest.fn().mockImplementation(() => {
return {
close: mockSerialPortClose,
constructor: mockSerialPortConstructor,
emit: () => {},
on: () => {},
once: mockSerialPortOnce,
open: mockSerialPortOpen,
pipe: mockSerialPortPipe,
set: mockSerialPortSet,
write: mockSerialPortWrite,
flush: mockSerialPortFlush,
isOpen: mockSerialPortIsOpen,
};
}),
};
jest.mock('serialport', () => {
return jest.fn().mockImplementation(() => {
return {
close: mockSerialPortClose,
constructor: mockSerialPortConstructor,
emit: () => {},
on: () => {},
once: mockSerialPortOnce,
open: mockSerialPortOpen,
pipe: mockSerialPortPipe,
set: mockSerialPortSet,
write: mockSerialPortWrite,
flush: mockSerialPortFlush,
isOpen: mockSerialPortIsOpen,
};
});
});

const mockSocketSetNoDelay = jest.fn();
Expand Down Expand Up @@ -143,7 +141,8 @@ describe('ZNP', () => {

expect(SerialPort).toHaveBeenCalledTimes(1);
expect(SerialPort).toHaveBeenCalledWith(
{"path": "/dev/ttyACM0", "autoOpen": false, "baudRate": 100, "rtscts": true},
"/dev/ttyACM0",
{"autoOpen": false, "baudRate": 100, "rtscts": true},
);

expect(mockSerialPortPipe).toHaveBeenCalledTimes(1);
Expand All @@ -158,7 +157,8 @@ describe('ZNP', () => {

expect(SerialPort).toHaveBeenCalledTimes(1);
expect(SerialPort).toHaveBeenCalledWith(
{"path": "/dev/ttyACM0", "autoOpen": false, "baudRate": 100, "rtscts": true},
"/dev/ttyACM0",
{"autoOpen": false, "baudRate": 100, "rtscts": true},
);

expect(mockSerialPortPipe).toHaveBeenCalledTimes(1);
Expand All @@ -174,7 +174,8 @@ describe('ZNP', () => {

expect(SerialPort).toHaveBeenCalledTimes(1);
expect(SerialPort).toHaveBeenCalledWith(
{"path": "/dev/ttyACM0", "autoOpen": false, "baudRate": 115200, "rtscts": false},
"/dev/ttyACM0",
{"autoOpen": false, "baudRate": 115200, "rtscts": false},
);

expect(mockSerialPortPipe).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -283,7 +284,8 @@ describe('ZNP', () => {

expect(SerialPort).toHaveBeenCalledTimes(1);
expect(SerialPort).toHaveBeenCalledWith(
{"path": "/dev/ttyACM0", "autoOpen": false, "baudRate": 100, "rtscts": true},
"/dev/ttyACM0",
{"autoOpen": false, "baudRate": 100, "rtscts": true},
);

expect(error).toEqual(new Error("Error while opening serialport 'failed!'"));
Expand All @@ -308,7 +310,8 @@ describe('ZNP', () => {

expect(SerialPort).toHaveBeenCalledTimes(1);
expect(SerialPort).toHaveBeenCalledWith(
{"path": "/dev/ttyACM0", "autoOpen": false, "baudRate": 100, "rtscts": true},
"/dev/ttyACM0",
{"autoOpen": false, "baudRate": 100, "rtscts": true},
);

expect(error).toEqual(new Error("Error while opening serialport 'failed!'"));
Expand Down

0 comments on commit 022136a

Please sign in to comment.