Skip to content

Commit

Permalink
Merge pull request #110 from particle-iot/chore/add-hidden-networks
Browse files Browse the repository at this point in the history
Add hidden network key to join networks
  • Loading branch information
keeramis authored Jun 3, 2024
2 parents 8370c78 + bc8fd24 commit 93a6940
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/wifi-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const WifiDevice = base => class extends base {
* @param {Object} options See sendControlRequest(), same options are here.
* @return {ProtobufInteraction} - empty response
*/
async joinNewWifiNetwork({ ssid, security, password = null }, options) {
async joinNewWifiNetwork({ ssid, security, password = null, hidden }, options) {
let dataPayload;
if (password === null) {
dataPayload = {
Expand All @@ -82,6 +82,7 @@ const WifiDevice = base => class extends base {
dataPayload = {
ssid,
bssid: null,
hidden: hidden === true,
security: security ? WiFiSecurity.toProtobuf(security) : null,
credentials: {
type: 1, // CredentialsType.PASSWORD
Expand Down Expand Up @@ -187,7 +188,7 @@ const WifiDevice = base => class extends base {
* @param {Object} options See sendControlRequest(), same options are here.
* @return {ProtobufInteraction} - empty response
*/
async setWifiCredentials({ ssid, security, password = null }, options) {
async setWifiCredentials({ ssid, security, password = null, hidden }, options) {
let dataPayload;
if (password === null) {
dataPayload = {
Expand All @@ -199,6 +200,7 @@ const WifiDevice = base => class extends base {
dataPayload = {
ssid,
bssid: null,
hidden: hidden === true,
security : security ? WiFiSecurity.toProtobuf(security) : null,
credentials: {
type: 1, // CredentialsType.PASSWORD
Expand Down
29 changes: 29 additions & 0 deletions src/wifi-device.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,35 @@ describe('WifiDevice', () => {
ssid,
bssid: null,
security: null,
hidden: false,
credentials: {
type: 1,
password
},
}
);
expect(wifiDevice.sendProtobufRequest.firstCall.args[2]).to.eql(undefined);
});

it('Sends wifi.JoinNewNetworkRequest protobuf message with correct data for hidden network', async () => {
const fakeReply = {
constructor: {
name: 'JoinNewNetworkReply'
}
};
sinon.stub(wifiDevice, 'sendProtobufRequest').resolves(fakeReply);
const result = await wifiDevice.joinNewWifiNetwork({ ssid, password, hidden: true });

expect(result).to.eql(fakeReply);
expect(wifiDevice.sendProtobufRequest).to.have.property('callCount', 1);
expect(wifiDevice.sendProtobufRequest.firstCall.args).to.have.lengthOf(3);
expect(wifiDevice.sendProtobufRequest.firstCall.args[0]).to.eql('wifi.JoinNewNetworkRequest');
expect(wifiDevice.sendProtobufRequest.firstCall.args[1]).to.eql(
{
ssid,
bssid: null,
security: null,
hidden: true,
credentials: {
type: 1,
password
Expand Down

0 comments on commit 93a6940

Please sign in to comment.