Skip to content

Commit

Permalink
fix: use zwave-js guessFirmwareFileFormat function (#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando authored Feb 8, 2021
1 parent 656e56d commit 6a9931f
Showing 1 changed file with 3 additions and 20 deletions.
23 changes: 3 additions & 20 deletions lib/ZwaveClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
NodeStatus,
InterviewStage,
extractFirmware,
guessFirmwareFileFormat,
CommandClass,
libVersion
} = require('zwave-js')
Expand Down Expand Up @@ -2209,25 +2210,7 @@ ZwaveClient.prototype.refreshInfo = async function (nodeId) {

throw Error('Driver is closed')
}
/**
* Try to guess the firmware format
*
* @param {string} filename
* @param {Buffer} firmware
* @returns {import('zwave-js').FirmwareFileFormat} The firmware format
*/
function guessFirmwareFormat (filename, firmware) {
if (
(filename.endsWith('.exe') || filename.endsWith('.ex_')) &&
firmware.includes(Buffer.from('Aeon Labs', 'utf8'))
) {
return 'aeotec'
} else if (/\.(hex|ota|otz)$/.test(filename)) {
return filename.slice(-3)
} else {
throw new Error('could not detect firmware format')
}
}

/**
* Start a frimware uddate
*
Expand All @@ -2254,7 +2237,7 @@ ZwaveClient.prototype.beginFirmwareUpdate = async function (

let actualFirmware
try {
const format = guessFirmwareFormat(fileName, data)
const format = guessFirmwareFileFormat(fileName, data)
actualFirmware = extractFirmware(data, format)
} catch (e) {
throw Error('Unable to extract firmware from file: ' + e.message)
Expand Down

0 comments on commit 6a9931f

Please sign in to comment.