From 793d716917d81de9e277579397b6c8e54cfff690 Mon Sep 17 00:00:00 2001 From: keeramis Date: Wed, 29 May 2024 14:38:07 -0700 Subject: [PATCH] Fix device left hanging --- src/cli/wifi.js | 8 ++++++-- src/cmd/serial.js | 4 +++- src/cmd/wifi.js | 8 ++++++-- test/e2e/wifi.e2e.js | 28 +++++++++++++++++++--------- 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/cli/wifi.js b/src/cli/wifi.js index e1d6c2e9b..dc1af96d2 100644 --- a/src/cli/wifi.js +++ b/src/cli/wifi.js @@ -91,10 +91,14 @@ module.exports = ({ commandProcessor, root }) => { }); commandProcessor.createCommand(wifi, 'remove', 'Removes a wifi network from the device', { - params: '', + options: Object.assign({ + 'ssid': { + description: 'The name of the network to remove' + } + }, portOption), handler: (args) => { const WiFiCommands = require('../cmd/wifi'); - return new WiFiCommands().removeNetwork(args.params.ssid); + return new WiFiCommands().removeNetwork(args); }, examples: { '$0 $command ssid': 'Removes a network specified by SSID from the device', diff --git a/src/cmd/serial.js b/src/cmd/serial.js index 0ef2ba2d6..7ada8215d 100644 --- a/src/cmd/serial.js +++ b/src/cmd/serial.js @@ -260,7 +260,7 @@ module.exports = class SerialCommand extends CLICommandBase { // Obtain system firmware version fwVer = device.firmwareVersion; - + // If the device is a cellular device, obtain imei and iccid @@ -531,6 +531,8 @@ module.exports = class SerialCommand extends CLICommandBase { } const fwVer = device.firmwareVersion; + await device.close(); + // XXX: Firmware version TBD if (semver.gte(fwVer, '6.2.0')) { this.ui.stdout.write(`${chalk.yellow('[Recommendation]')}${os.EOL}`); diff --git a/src/cmd/wifi.js b/src/cmd/wifi.js index bf550c4c9..9a1b5f1e4 100644 --- a/src/cmd/wifi.js +++ b/src/cmd/wifi.js @@ -82,7 +82,11 @@ module.exports = class WiFiCommands extends CLICommandBase { }); } - async removeNetwork(ssid) { + async removeNetwork(args) { + const { ssid } = args; + if (!ssid) { + throw new Error('Please provide a network name to remove using the --ssid flag.'); + } await this._withDevice(async () => { await this.removeWifi(ssid); }); @@ -136,7 +140,7 @@ module.exports = class WiFiCommands extends CLICommandBase { error.isUsageError = true; throw error; } - return { ssid: network, security: this._convertToKnownSecType(security), password }; + return { ssid: network, security: this._convertToKnownSecType(security), password }; } async _getNetworkToConnect({ prompt = true } = { }) { diff --git a/test/e2e/wifi.e2e.js b/test/e2e/wifi.e2e.js index e1c49bd58..a51d5d851 100644 --- a/test/e2e/wifi.e2e.js +++ b/test/e2e/wifi.e2e.js @@ -16,16 +16,17 @@ describe('Wi-Fi Commands [@device,@wifi]', () => { 'Help: particle help wifi ', '', 'Commands:', - ' add Adds a WiFi network to your device', - ' join Joins a wifi network', - ' clear Clears the list of wifi networks on your device', - ' list Lists the wifi networks on your device', - ' remove Removes a wifi network from the device', + ' add Adds a WiFi network to your device', + ' join Joins a wifi network', + ' clear Clears the list of wifi networks on your device', + ' list Lists the wifi networks on your device', + ' remove Removes a wifi network from the device', ' current Gets the current wifi network', '', 'Global Options:', ' -v, --verbose Increases how much logging to display [count]', - ' -q, --quiet Decreases how much logging to display [count]' + ' -q, --quiet Decreases how much logging to display [count]', + '' ]; after(async () => { @@ -79,7 +80,16 @@ describe('Wi-Fi Commands [@device,@wifi]', () => { const { stdout, stderr, exitCode } = await cli.run(['wifi', 'join', '--ssid', WIFI_SSID]); expect(listStdout).to.include(WIFI_SSID); - expect(stdout).to.include(`Wi-Fi network '${WIFI_SSID}' configured and joined successfully.`); + expect(stdout).to.include(`Wi-Fi network '${WIFI_SSID}' joined successfully.`); + expect(stderr).to.equal(''); + expect(exitCode).to.equal(0); + }); + + it('Fetches the current network the device is connected to', async () => { + // Let the device join a network and then clear it + const { stdout, stderr, exitCode } = await cli.run(['wifi', 'current']); + + expect(stdout).to.include(WIFI_SSID); expect(stderr).to.equal(''); expect(exitCode).to.equal(0); }); @@ -105,8 +115,8 @@ describe('Wi-Fi Commands [@device,@wifi]', () => { }); it('Clears networks from the device', async () => { - // Let the device join a network and then clear it - await cli.run(['wifi', 'join', '--ssid', WIFI_SSID]); + // Let the device add a network and then clear it + await cli.run(['wifi', 'add', '--ssid', WIFI_SSID]); const { stdout: listStdoutBeforeClearing } = await cli.run(['wifi', 'list']); const { stdout, stderr, exitCode } = await cli.run(['wifi', 'clear']); const { stdout : listStdoutAfterClearing } = await cli.run(['wifi', 'list']);