Skip to content

Commit

Permalink
fix(wifi): getWifiInfo in enable/reset
Browse files Browse the repository at this point in the history
  • Loading branch information
HipsterBrown committed Aug 14, 2016
1 parent e295b3e commit 86cabc6
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions node/tessel-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -1142,16 +1142,10 @@ Tessel.LED.prototype.read = function(callback) {

Tessel.Wifi = function() {
var state = {
settings: {},
connected: false
settings: {}
};

Object.defineProperties(this, {
connected: {
set: (value) => {
state.connected = value;
}
},
settings: {
get: () => state.settings,
set: (settings) => {
Expand All @@ -1171,9 +1165,10 @@ Tessel.Wifi.prototype.enable = function(callback) {
turnOnWifi()
.then(commitWireless)
.then(restartWifi)
.then(() => {
.then(getWifiInfo)
.then((network) => {
Object.assign(this.settings, network);
this.emit('connect', this.settings);
this.connected = true;
callback();
})
.catch((error) => {
Expand All @@ -1192,7 +1187,6 @@ Tessel.Wifi.prototype.disable = function(callback) {
.then(commitWireless)
.then(restartWifi)
.then(() => {
this.connected = false;
this.emit('disconnect');
callback();
})
Expand All @@ -1207,11 +1201,11 @@ Tessel.Wifi.prototype.reset = function(callback) {
callback = function() {};
}

this.connected = false;
this.emit('disconnect', 'Resetting connection');
restartWifi()
.then(() => {
this.connected = true;
.then(getWifiInfo)
.then((network) => {
Object.assign(this.settings, network);
this.emit('connect', this.settings);
callback();
})
Expand Down Expand Up @@ -1242,7 +1236,7 @@ Tessel.Wifi.prototype.connection = function(callback) {
callback(error);
});
} else {
return callback(null, null);
callback(null, null);
}
})
.catch((error) => {
Expand Down Expand Up @@ -1278,7 +1272,6 @@ Tessel.Wifi.prototype.connect = function(settings, callback) {
delete settings.password;

this.settings = Object.assign(network, settings);
this.connected = true;
this.emit('connect', this.settings);

callback(null, this.settings);
Expand Down

0 comments on commit 86cabc6

Please sign in to comment.