Skip to content

Commit

Permalink
fix(miio): Allow setting new wifi credentials when provisioned
Browse files Browse the repository at this point in the history
fixes #657
  • Loading branch information
Hypfer committed Jun 19, 2021
1 parent de45f72 commit 32a12cf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 34 deletions.
16 changes: 16 additions & 0 deletions backend/lib/robots/MiioValetudoRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,22 @@ class MiioValetudoRobot extends ValetudoRobot {
}
}

/**
* Sends a {'method': method, 'params': args} message to the robot.
* Only uses the local socket
*
* @public
* @param {string} method
* @param {object|Array} args
* @param {object} options
* @param {number=} options.retries
* @param {number=} options.timeout custom timeout in milliseconds
* @returns {Promise<object>}
*/
sendLocal(method, args = [], options = {}) {
return this.localSocket.sendMessage(method, args, options);
}

/**
* Sends a json object to cloud socket.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class MiioWifiConfigurationCapability extends LinuxWifiConfigurationCapability {
wifiConfig.credentials.type === ValetudoWifiConfiguration.CREDENTIALS_TYPE.WPA2_PSK &&
wifiConfig.credentials.typeSpecificSettings && wifiConfig.credentials.typeSpecificSettings.password
) {
await this.robot.sendCommand("miIO.config_router", {
//This command will only work when received on the local interface!
await this.robot.sendLocal("miIO.config_router", {
"ssid": wifiConfig.ssid,
"passwd": wifiConfig.credentials.typeSpecificSettings.password,
"uid": 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
const LinuxWifiConfigurationCapability = require("../../common/linuxCapabilities/LinuxWifiConfigurationCapability");
const MiioWifiConfigurationCapability = require("../../common/miioCapabilities/MiioWifiConfigurationCapability");
const ValetudoWifiConfiguration = require("../../../entities/core/ValetudoWifiConfiguration");

/**
* @extends LinuxWifiConfigurationCapability<import("../RoborockValetudoRobot")>
*/
class RoborockWifiConfigurationCapability extends LinuxWifiConfigurationCapability {

getWifiInterface() {
return "wlan0";
}

class RoborockWifiConfigurationCapability extends MiioWifiConfigurationCapability {
/**
* @returns {Promise<ValetudoWifiConfiguration>}
*/
Expand Down Expand Up @@ -42,29 +34,6 @@ class RoborockWifiConfigurationCapability extends LinuxWifiConfigurationCapabili

return new ValetudoWifiConfiguration(output);
}

/**
* @param {import("../../../entities/core/ValetudoWifiConfiguration")} wifiConfig
* @returns {Promise<void>}
*/
async setWifiConfiguration(wifiConfig) {
if (
wifiConfig && wifiConfig.ssid && wifiConfig.credentials &&
wifiConfig.credentials.type === ValetudoWifiConfiguration.CREDENTIALS_TYPE.WPA2_PSK &&
wifiConfig.credentials.typeSpecificSettings && wifiConfig.credentials.typeSpecificSettings.password
) {
await this.robot.sendCommand("miIO.config_router", {
"ssid": wifiConfig.ssid,
"passwd": wifiConfig.credentials.typeSpecificSettings.password,
"uid": 0,
"cc": "de",
"country_domain": "de",
"config_type": "app"
}, {});
} else {
throw new Error("Invalid wifiConfig");
}
}
}

module.exports = RoborockWifiConfigurationCapability;

0 comments on commit 32a12cf

Please sign in to comment.