Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: zwave-js@14.3.0 and @zwave-js/server@1.40.0 #3960

Merged
merged 11 commits into from
Nov 12, 2024
4 changes: 2 additions & 2 deletions api/lib/ZnifferManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export default class ZnifferManager extends TypedEventEmitter<ZnifferManagerEven

private parseFrame(
frame: Frame | CorruptedFrame,
rawData: Buffer,
rawData: Uint8Array,
timestamp = Date.now(),
): SocketFrame {
const socketFrame: SocketFrame = {
Expand Down Expand Up @@ -196,7 +196,7 @@ export default class ZnifferManager extends TypedEventEmitter<ZnifferManagerEven
return this.zniffer.capturedFrames.map((frame) => {
return this.parseFrame(
frame.parsedFrame,
frame.frameData,
Buffer.from(frame.frameData),
frame.timestamp.getTime(),
)
})
Expand Down
15 changes: 8 additions & 7 deletions api/lib/ZwaveClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ import { ConfigManager, DeviceConfig } from '@zwave-js/config'
import { readFile } from 'fs/promises'
import backupManager, { NVM_BACKUP_PREFIX } from './BackupManager'
import { socketEvents } from './SocketEvents'
import { isUint8Array } from 'util/types'

export const deviceConfigPriorityDir = storeDir + '/config'

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

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

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

return { data, fileName }
return { data: Buffer.from(data.buffer), fileName }
}

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

const zwaveNode = endpoint.getNodeUnsafe()
const zwaveNode = endpoint.tryGetNode()

if (!zwaveNode) {
this.logNode(
Expand Down Expand Up @@ -6420,13 +6421,13 @@ class ZwaveClient extends TypedEventEmitter<ZwaveClientEventCallbacks> {
}

let newValue = args.newValue
if (Buffer.isBuffer(newValue)) {
if (isUint8Array(newValue)) {
// encode Buffers as HEX strings
newValue = utils.buffer2hex(newValue)
}

let prevValue = args.prevValue
if (Buffer.isBuffer(prevValue)) {
if (isUint8Array(prevValue)) {
// encode Buffers as HEX strings
prevValue = utils.buffer2hex(prevValue)
}
Expand Down Expand Up @@ -6489,8 +6490,8 @@ class ZwaveClient extends TypedEventEmitter<ZwaveClientEventCallbacks> {
// ------- Utils ------------------------

private _parseNotification(parameters) {
if (Buffer.isBuffer(parameters)) {
return parameters.toString('hex')
if (isUint8Array(parameters)) {
return Buffer.from(parameters.buffer).toString('hex')
} else if (parameters instanceof Duration) {
return parameters.toMilliseconds()
} else {
Expand Down
4 changes: 2 additions & 2 deletions api/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ export function bufferFromHex(hex: string): Buffer {
/**
* Converts a buffer to an hex string
*/
export function buffer2hex(buffer: Buffer): string {
export function buffer2hex(buffer: Uint8Array): string {
if (buffer.length === 0) return ''
return `0x${buffer.toString('hex')}`
return `0x${Buffer.from(buffer.buffer).toString('hex')}`
}

export function allSettled(promises: Promise<any>[]): Promise<any> {
Expand Down
17 changes: 4 additions & 13 deletions esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,10 @@ async function main() {
console.log(`Build took ${Date.now() - start}ms`)
await printSize(outfile)

const content = (await readFile(outfile, 'utf-8'))
.replace(
/__dirname, "\.\.\/"/g,
'__dirname, "./node_modules/@serialport/bindings-cpp"',
)
.replace(
`__dirname, "../package.json"`,
`__dirname, "./node_modules/@zwave-js/config/package.json"`,
)
.replace(
`__dirname, "../config"`,
`__dirname, "./node_modules/@zwave-js/config/config"`,
)
const content = (await readFile(outfile, 'utf-8')).replace(
/__dirname, "\.\.\/"/g,
'__dirname, "./node_modules/@serialport/bindings-cpp"',
)

await writeFile(outfile, content)

Expand Down
Loading