Skip to content

Commit

Permalink
Fix device left hanging
Browse files Browse the repository at this point in the history
  • Loading branch information
keeramis committed May 29, 2024
1 parent d5fa264 commit 793d716
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
8 changes: 6 additions & 2 deletions src/cli/wifi.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ module.exports = ({ commandProcessor, root }) => {
});

commandProcessor.createCommand(wifi, 'remove', 'Removes a wifi network from the device', {
params: '<ssid>',
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',
Expand Down
4 changes: 3 additions & 1 deletion src/cmd/serial.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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}`);
Expand Down
8 changes: 6 additions & 2 deletions src/cmd/wifi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -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 } = { }) {
Expand Down
28 changes: 19 additions & 9 deletions test/e2e/wifi.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ describe('Wi-Fi Commands [@device,@wifi]', () => {
'Help: particle help wifi <command>',
'',
'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 () => {
Expand Down Expand Up @@ -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);
});
Expand All @@ -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']);
Expand Down

0 comments on commit 793d716

Please sign in to comment.