Skip to content

Commit b2c0372

Browse files
Co-authored-by: Daniel Lando <[email protected]>
1 parent 4d68323 commit b2c0372

File tree

6 files changed

+4337
-4211
lines changed

6 files changed

+4337
-4211
lines changed

api/lib/ZnifferManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export default class ZnifferManager extends TypedEventEmitter<ZnifferManagerEven
144144

145145
private parseFrame(
146146
frame: Frame | CorruptedFrame,
147-
rawData: Buffer,
147+
rawData: Uint8Array,
148148
timestamp = Date.now(),
149149
): SocketFrame {
150150
const socketFrame: SocketFrame = {
@@ -196,7 +196,7 @@ export default class ZnifferManager extends TypedEventEmitter<ZnifferManagerEven
196196
return this.zniffer.capturedFrames.map((frame) => {
197197
return this.parseFrame(
198198
frame.parsedFrame,
199-
frame.frameData,
199+
Buffer.from(frame.frameData),
200200
frame.timestamp.getTime(),
201201
)
202202
})

api/lib/ZwaveClient.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ import { ConfigManager, DeviceConfig } from '@zwave-js/config'
124124
import { readFile } from 'fs/promises'
125125
import backupManager, { NVM_BACKUP_PREFIX } from './BackupManager'
126126
import { socketEvents } from './SocketEvents'
127+
import { isUint8Array } from 'util/types'
127128

128129
export const deviceConfigPriorityDir = storeDir + '/config'
129130

@@ -4912,7 +4913,7 @@ class ZwaveClient extends TypedEventEmitter<ZwaveClientEventCallbacks> {
49124913
logger.warn('Inclusion aborted')
49134914
}
49144915

4915-
async backupNVMRaw() {
4916+
async backupNVMRaw(): Promise<{ data: Buffer; fileName: string }> {
49164917
if (!this.driverReady) {
49174918
throw new DriverNotReadyError()
49184919
}
@@ -4931,7 +4932,7 @@ class ZwaveClient extends TypedEventEmitter<ZwaveClientEventCallbacks> {
49314932

49324933
await writeFile(utils.joinPath(nvmBackupsDir, fileName + '.bin'), data)
49334934

4934-
return { data, fileName }
4935+
return { data: Buffer.from(data.buffer), fileName }
49354936
}
49364937

49374938
private _onBackupNVMProgress(bytesRead: number, totalBytes: number) {
@@ -5621,7 +5622,7 @@ class ZwaveClient extends TypedEventEmitter<ZwaveClientEventCallbacks> {
56215622
private _onNodeNotification: ZWaveNotificationCallback = (...parms) => {
56225623
const [endpoint, ccId, args] = parms
56235624

5624-
const zwaveNode = endpoint.getNodeUnsafe()
5625+
const zwaveNode = endpoint.tryGetNode()
56255626

56265627
if (!zwaveNode) {
56275628
this.logNode(
@@ -6420,13 +6421,13 @@ class ZwaveClient extends TypedEventEmitter<ZwaveClientEventCallbacks> {
64206421
}
64216422

64226423
let newValue = args.newValue
6423-
if (Buffer.isBuffer(newValue)) {
6424+
if (isUint8Array(newValue)) {
64246425
// encode Buffers as HEX strings
64256426
newValue = utils.buffer2hex(newValue)
64266427
}
64276428

64286429
let prevValue = args.prevValue
6429-
if (Buffer.isBuffer(prevValue)) {
6430+
if (isUint8Array(prevValue)) {
64306431
// encode Buffers as HEX strings
64316432
prevValue = utils.buffer2hex(prevValue)
64326433
}
@@ -6489,8 +6490,8 @@ class ZwaveClient extends TypedEventEmitter<ZwaveClientEventCallbacks> {
64896490
// ------- Utils ------------------------
64906491

64916492
private _parseNotification(parameters) {
6492-
if (Buffer.isBuffer(parameters)) {
6493-
return parameters.toString('hex')
6493+
if (isUint8Array(parameters)) {
6494+
return Buffer.from(parameters.buffer).toString('hex')
64946495
} else if (parameters instanceof Duration) {
64956496
return parameters.toMilliseconds()
64966497
} else {

api/lib/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,9 @@ export function bufferFromHex(hex: string): Buffer {
281281
/**
282282
* Converts a buffer to an hex string
283283
*/
284-
export function buffer2hex(buffer: Buffer): string {
284+
export function buffer2hex(buffer: Uint8Array): string {
285285
if (buffer.length === 0) return ''
286-
return `0x${buffer.toString('hex')}`
286+
return `0x${Buffer.from(buffer.buffer).toString('hex')}`
287287
}
288288

289289
export function allSettled(promises: Promise<any>[]): Promise<any> {

esbuild.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,10 @@ async function main() {
115115
console.log(`Build took ${Date.now() - start}ms`)
116116
await printSize(outfile)
117117

118-
const content = (await readFile(outfile, 'utf-8'))
119-
.replace(
120-
/__dirname, "\.\.\/"/g,
121-
'__dirname, "./node_modules/@serialport/bindings-cpp"',
122-
)
123-
.replace(
124-
`__dirname, "../package.json"`,
125-
`__dirname, "./node_modules/@zwave-js/config/package.json"`,
126-
)
127-
.replace(
128-
`__dirname, "../config"`,
129-
`__dirname, "./node_modules/@zwave-js/config/config"`,
130-
)
118+
const content = (await readFile(outfile, 'utf-8')).replace(
119+
/__dirname, "\.\.\/"/g,
120+
'__dirname, "./node_modules/@serialport/bindings-cpp"',
121+
)
131122

132123
await writeFile(outfile, content)
133124

0 commit comments

Comments
 (0)